Add app info and instrument controls
This commit is contained in:
1 parent
e23825cdb1
commit
9d8f277971
38 files changed
+4001
-257
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { defineConfig } from 'vitepress';
|
||||
|
||||
export default defineConfig({
|
||||
title: 'BeatHound Documentation',
|
||||
description: 'Easy-English user and software documentation for BeatHound.',
|
||||
cleanUrls: true,
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{ text: 'Home', link: '/' },
|
||||
{ text: 'User guide', link: '/software-guide' },
|
||||
{ text: 'Software documentation', link: '/software-documentation' },
|
||||
],
|
||||
sidebar: [
|
||||
{
|
||||
text: 'BeatHound',
|
||||
items: [
|
||||
{ text: 'Overview', link: '/' },
|
||||
{ text: 'User and development guide', link: '/software-guide' },
|
||||
{ text: 'Software documentation', link: '/software-documentation' },
|
||||
],
|
||||
},
|
||||
],
|
||||
search: {
|
||||
provider: 'local',
|
||||
},
|
||||
outline: {
|
||||
level: [2, 3],
|
||||
label: 'On this page',
|
||||
},
|
||||
socialLinks: [],
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
layout: home
|
||||
|
||||
hero:
|
||||
name: BeatHound
|
||||
text: Software documentation
|
||||
tagline: Learn how to use the beat maker and how its code works.
|
||||
actions:
|
||||
- theme: brand
|
||||
text: Read the technical documentation
|
||||
link: /software-documentation
|
||||
- theme: alt
|
||||
text: Use BeatHound
|
||||
link: /software-guide
|
||||
|
||||
features:
|
||||
- title: Understand the architecture
|
||||
details: Follow the app from startup through state, the circular timeline, and sound playback.
|
||||
- title: Explore the modules
|
||||
details: See what each component, hook, domain file, and audio module does.
|
||||
- title: Change the software
|
||||
details: Learn how to add a sound or template and how to check your changes.
|
||||
---
|
||||
|
||||
## Documentation pages
|
||||
|
||||
- [Software documentation](/software-documentation) — system design, data flow, timing, audio, components, hooks, tests, and extension points.
|
||||
- [User and development guide](/software-guide) — using BeatHound, running it on your computer, and an overview of its source files.
|
||||
|
||||
BeatHound is a React and TypeScript app. It runs in a browser and creates its sounds with the Web Audio API. This site explains the app in easy English for users and developers.
|
||||
@@ -0,0 +1,287 @@
|
||||
# BeatHound Software Documentation
|
||||
|
||||
This document describes how BeatHound works inside. It is for people who want to read, change, or test the code. Short explanations are used for technical ideas.
|
||||
|
||||
For instructions on using the app, see the [user and development guide](software-guide.md).
|
||||
|
||||
## 1. System overview
|
||||
|
||||
BeatHound is a single-page web app. It runs in the user's browser. React draws the page and keeps the current loop state. The Web Audio API creates the sound.
|
||||
|
||||
The app has no backend service. It does not send loop data to an API or save it in browser storage. Reloading the page starts a new empty loop.
|
||||
|
||||
Main tools:
|
||||
|
||||
- **React** builds the interface and manages state.
|
||||
- **TypeScript** checks types before the app is built.
|
||||
- **Ionic React** provides page and control components.
|
||||
- **Ionicons** provides the control icons.
|
||||
- **Vite** runs the local development server and builds the static site.
|
||||
- **Vitest** runs the tests.
|
||||
- **Web Audio API** creates the sounds in the browser.
|
||||
|
||||
## 2. Start-up and data flow
|
||||
|
||||
### Start-up flow
|
||||
|
||||
1. `index.html` defines the page, metadata, and a `root` element.
|
||||
2. `src/main.tsx` loads Ionic CSS and `src/styles.css`, sets up Ionic, and mounts React.
|
||||
3. `src/App.tsx` creates the shared page shell, calls `useBeatStudio()`, and keeps the active view.
|
||||
4. `AppHeader` lets the user choose the Beat studio or About view from the top-right menu.
|
||||
5. `StudioView` displays the sequencer. `AboutView` displays general app information.
|
||||
6. `useBeatStudio()` combines the sequencer hook and sound palette hook.
|
||||
7. Components receive values and callback functions as props. They display state and report user actions back to the hooks.
|
||||
|
||||
Most components do not own the loop data. The sequencer hook owns that data and passes the parts each component needs. The hook stays mounted in `App` while the user switches views, so the loop is still present when the user returns to the studio. Playback is stopped when the user opens the About view.
|
||||
|
||||
### Add a sound flow
|
||||
|
||||
1. `InstrumentSelector` shows categories from `INSTRUMENT_CATEGORIES` in `src/domain/instruments.ts` in an Ionic select.
|
||||
2. The user chooses a category and presses the plus button. A popover then shows only that category's instruments.
|
||||
3. Choosing an instrument calls `useBeatStudio.addSound()`. It activates the instrument color and calls `useBeatSequencer.addBeat()`.
|
||||
4. `addBeat()` creates a unique ID and asks `getNextAvailableStep()` for an unused whole-number step.
|
||||
5. The `beat-added` action updates reducer state. The new point becomes selected, and its sound ring becomes focused.
|
||||
6. React renders the new point and updates the legend. If the instrument supports pitch, the toolbar also shows its pitch control.
|
||||
|
||||
`getNextAvailableStep()` checks whole steps from the start of the current loop. If all whole steps are occupied, it returns step zero. This does not prevent two points from sharing a step.
|
||||
|
||||
### Template flow
|
||||
|
||||
1. `BeatTemplateSelector` reads the menu entries from `BEAT_TEMPLATES`.
|
||||
2. Selecting an entry calls `useBeatStudio.applyTemplate()`.
|
||||
3. `useBeatSequencer.loadTemplate()` creates fresh IDs for its points and dispatches `template-loaded` with the points, tempo, and meter.
|
||||
4. Playback position is reset. The palette activates each sound used by the template.
|
||||
|
||||
Templates replace the loop; they do not add points to the current loop. The Empty template loads no points and restores its own tempo and meter.
|
||||
|
||||
## 3. Core data and state
|
||||
|
||||
### Sound point
|
||||
|
||||
The `BeatPoint` interface in `src/domain/sequencer.ts` is the data for one point:
|
||||
|
||||
| Field | Type | Meaning |
|
||||
| --- | --- | --- |
|
||||
| `id` | `string` | Unique ID for this point. |
|
||||
| `soundId` | `InstrumentId` | Instrument type, such as `kick`, `piano`, or `shaker`. |
|
||||
| `step` | `number` | Position in the loop. It can be a whole or fractional number. |
|
||||
| `pitchSemitones` | `number?` | Optional pitch offset for instruments that support pitch. |
|
||||
|
||||
The instrument ID type comes from the keys in `src/domain/instruments.ts`. Adding an instrument definition updates the TypeScript type and instrument catalog. `src/domain/sounds.ts` re-exports the older names for compatibility.
|
||||
|
||||
### Sequencer state
|
||||
|
||||
`SequencerState` in `src/domain/sequencerReducer.ts` contains:
|
||||
|
||||
| Field | Meaning |
|
||||
| --- | --- |
|
||||
| `beats` | All sound points in the current loop. |
|
||||
| `selectedBeatId` | ID of the point selected for moving or deleting, or `null`. |
|
||||
| `focusedSoundId` | Sound ring currently selected, or `null`. |
|
||||
| `tempoBpm` | Playback speed in beats per minute. |
|
||||
| `beatsPerBar` | Number of beats in the loop. |
|
||||
|
||||
Playback status and the play marker are kept separately by `useBeatPlayback`. Sound colors are kept by `useSoundPalette`. This separates musical data from playback and display details.
|
||||
|
||||
### Reducer actions
|
||||
|
||||
`sequencerReducer()` is a pure state update function. It receives the current state and one named action, then returns the next state. Actions cover adding, moving, pitching, selecting, and removing points; selecting an instrument; changing tempo and meter; and loading a template.
|
||||
|
||||
Important state rules:
|
||||
|
||||
- Selecting a point also focuses that point's sound ring.
|
||||
- Selecting a ring clears the selected point.
|
||||
- Removing a selected point removes only that point.
|
||||
- Removing a focused ring removes every point of that sound type.
|
||||
- Tempo changes are rounded and clamped to 60–180 BPM.
|
||||
- Pitch changes are rounded and clamped to two octaves around the instrument's base note. Pitch is stored on the individual beat point.
|
||||
- A shorter meter hides points beyond its loop length; the points remain in state and can become visible if the meter is lengthened again.
|
||||
- Loading a template replaces the point list and sets the template tempo and meter.
|
||||
|
||||
`assertNever()` in the reducer makes TypeScript report an error if a new action type is added but not handled by the switch statement.
|
||||
|
||||
## 4. Loop and timing model
|
||||
|
||||
The constants and calculations are in `src/domain/sequencer.ts`:
|
||||
|
||||
| Rule | Value |
|
||||
| --- | ---: |
|
||||
| Main steps per beat | 4 |
|
||||
| Playback subdivisions per main step | 4 |
|
||||
| Default meter | 4/4 |
|
||||
| Default tempo | 112 BPM |
|
||||
| Allowed tempo | 60–180 BPM |
|
||||
| Allowed beats per bar | 2, 3, 4, 5, 6, 7, or 8 |
|
||||
| Pitch range for supported instruments | ±24 semitones around the instrument's base note |
|
||||
|
||||
For a meter with `N` beats, the loop has `N × 4` main steps. A 4/4 loop has 16 main steps. Playback subdivides every main step into four ticks, so a 4/4 loop has 64 playback ticks.
|
||||
|
||||
`step` values are continuous while a point is dragged. Playback rounds the point to the nearest subdivision by multiplying its step by four and rounding. A fractional position such as `2.25` is a supported tick; a position such as `2.1` is played at the nearest supported tick.
|
||||
|
||||
### Tempo and tick duration
|
||||
|
||||
`getPlaybackTickDurationMs(tempoBpm)` returns:
|
||||
|
||||
```text
|
||||
60,000 milliseconds ÷ BPM ÷ 4 main steps per beat ÷ 4 ticks per main step
|
||||
```
|
||||
|
||||
At 120 BPM, one playback tick is 31.25 milliseconds. Playback uses `window.setInterval()` with this duration.
|
||||
|
||||
### Circular drawing
|
||||
|
||||
`src/domain/timeline.ts` contains math for converting positions:
|
||||
|
||||
- `getPointForStep()` converts a step to an `(x, y)` point in the SVG. Step zero is at the top; later steps move clockwise.
|
||||
- `getStepFromPosition()` converts pointer coordinates back to a step.
|
||||
- `wrapStepPosition()` keeps keyboard movement inside the loop.
|
||||
- `getSoundOrbitRadius()` gives each sound its own circle.
|
||||
- `getStackedPosition()` moves same-sound points that land on the same playback tick a little apart on screen, so both can be seen. This visual offset does not change their stored or played step.
|
||||
|
||||
The SVG uses a 600 by 600 view box. Pointer coordinates are scaled from the displayed size to that view box before the step is calculated.
|
||||
|
||||
## 5. Playback and audio
|
||||
|
||||
### Playback hook
|
||||
|
||||
`useBeatPlayback()` owns these playback values:
|
||||
|
||||
- `isPlaying`: whether the timer is running.
|
||||
- `isStarting`: whether the browser audio context is starting.
|
||||
- `currentStep`: the position shown by the play marker. It is `-1` when stopped.
|
||||
- `audioError`: a message to show when browser audio cannot start.
|
||||
|
||||
The hook keeps the latest beats and loop length in refs. The timer callback can then read current data without restarting only because the beat list changed.
|
||||
|
||||
When playback starts, the hook advances once immediately, then starts an interval. Each tick updates the play marker and plays every point whose rounded playback tick matches the current tick. The audio engine also receives that point's pitch offset. When playback stops, the current tick returns to the start. If there are no visible points, playback stops. Changing the meter wraps the current tick into the new loop length.
|
||||
|
||||
### Audio engine
|
||||
|
||||
`src/audio/AudioEngine.ts` owns one `AudioContext`:
|
||||
|
||||
1. `start()` checks for the browser's standard or WebKit audio context.
|
||||
2. It creates the context if needed and resumes it.
|
||||
3. `play(instrumentId, pitchSemitones)` looks up the instrument's function in `INSTRUMENT_VOICES` and calls it only when the context is running.
|
||||
4. `dispose()` closes the context when the hook is removed.
|
||||
|
||||
Audio starts after the user presses Play. This supports browser rules that require a user action before audio can play.
|
||||
|
||||
### Sound functions
|
||||
|
||||
`src/audio/instruments.ts` contains the Web Audio graphs for the catalog instruments. Drums and percussion use oscillators, filtered noise, or both. Bass, Keys, Strings, Winds, and Synth use pitched oscillator voices. Pitch-capable voices convert semitones to frequency with `baseFrequency × 2^(semitones / 12)`.
|
||||
|
||||
The `INSTRUMENT_VOICES` object in `src/audio/soundVoices.ts` maps each `InstrumentId` to its function. `AudioEngine` does not need an instrument-specific conditional. An instrument's `supportsPitch` value controls whether the toolbar displays the pitch slider.
|
||||
|
||||
### Timing limits
|
||||
|
||||
The app uses a JavaScript interval to decide when to play sounds. Browser scheduling can be delayed by a busy page, background tabs, or the device. The Web Audio API makes each sound itself, but this version does not schedule all future notes on the audio clock. For more precise timing, the playback scheduler would need to schedule audio events ahead of time with `AudioContext.currentTime`.
|
||||
|
||||
## 6. UI component and hook responsibilities
|
||||
|
||||
### Components
|
||||
|
||||
| Component | Responsibility |
|
||||
| --- | --- |
|
||||
| `App` | Creates the shared app shell, owns studio state, and selects the active view. |
|
||||
| `AppHeader` | Shows the brand and opens the view menu with the Ionic `ellipsisVertical` icon. |
|
||||
| `StudioView` | Displays the beat loop and template controls. |
|
||||
| `AboutView` | Displays project version, license, technology stack, repository, and issue tracker links. |
|
||||
| `BeatLoopPanel` | Connects timeline, meter, tempo, sound ring, selection hint, and delete action. |
|
||||
| `InstrumentSelector` | Selects a category; its plus button opens a menu of that category's instruments. |
|
||||
| `PitchControl` | Changes pitch for a selected point when its instrument supports pitch. |
|
||||
| `CircularTimeline` | Draws rings, ticks, points, and play marker; handles pointer and keyboard input. |
|
||||
| `TransportBar` | Starts/stops playback and holds the instrument selector and pitch control. |
|
||||
| `BeatTemplateSelector` | Displays and selects templates. |
|
||||
| `TempoControl` | Displays and changes tempo using an Ionic range. |
|
||||
| `TimeSignatureSelector` | Displays and changes beats per bar. |
|
||||
| `SoundRingSelector` | Selects one of the sound rings. |
|
||||
| `BeatSelectionHint` | Shows the selected point position or selected sound ring. |
|
||||
|
||||
### Hooks
|
||||
|
||||
| Hook | Responsibility |
|
||||
| --- | --- |
|
||||
| `useBeatStudio` | Joins sequencer actions with sound palette activation. |
|
||||
| `useBeatSequencer` | Owns reducer state and exposes typed sequencer operations to components. |
|
||||
| `useBeatPlayback` | Owns audio startup, tick timer, play marker, and playback errors. |
|
||||
| `useSoundPalette` | Assigns one stable color to each sound type activated in the current page session. |
|
||||
| `usePopoverDisclosure` | Tracks the open/closed state used for accessible popover labels. |
|
||||
|
||||
Components are mostly presentational: they receive state and callbacks through props. State updates happen in hooks and the reducer.
|
||||
|
||||
`AppView` in `src/views/viewTypes.ts` is the union of the supported view names: `studio` and `about`. The header reports a requested view to `App`; it does not render view content itself. `App` chooses the matching view component. This keeps navigation, the studio, and app information in separate modules.
|
||||
|
||||
`AboutView` reads its version, license URL, repository URL, and issue URL from `src/config/projectInfo.ts`. The version comes from `package.json`, so it stays in sync with the app package metadata. Project links are kept in one file so they can be updated without changing the view layout.
|
||||
|
||||
## 7. Input and accessibility behavior
|
||||
|
||||
`CircularTimeline` uses SVG groups and circles with button roles and accessible labels.
|
||||
|
||||
- Pointer-down on a sound point selects it and captures the pointer. Pointer movement changes its step. Pointer-up or pointer-cancel ends the drag.
|
||||
- Arrow keys move a focused point by one playback subdivision: `1 / PLAYBACK_SUBSTEPS_PER_STEP` of a main step.
|
||||
- Shift plus an arrow key moves by one full main step.
|
||||
- Arrow movement wraps from the end of the loop to its start, and from the start to its end.
|
||||
- Enter or Space on a sound orbit selects that sound ring.
|
||||
- Ionic controls provide labeled buttons, popovers, and range input for other settings.
|
||||
|
||||
The selection state is used by the trash button to decide whether to delete one point or all points on the focused ring.
|
||||
|
||||
## 8. Extend the software
|
||||
|
||||
### Add an instrument
|
||||
|
||||
1. Add its ID, label, description, category, and `supportsPitch` value in `src/domain/instruments.ts`.
|
||||
2. Add its ID to the matching entry in `INSTRUMENT_CATEGORIES` in the same file.
|
||||
3. Add a function that accepts an `AudioContext` and pitch value in `src/audio/instruments.ts`.
|
||||
4. Add an entry for the new ID in `INSTRUMENT_VOICES` in `src/audio/soundVoices.ts`.
|
||||
5. Add or update tests for catalog membership, pitch behavior, or new sound behavior.
|
||||
|
||||
The catalog drives the toolbar dropdown. TypeScript requires the voice map to include every `InstrumentId`. Sound colors are assigned by the palette hook. Avoid adding instrument-specific branches to the timeline or sequencer hook unless an instrument needs different behavior.
|
||||
|
||||
### Add a template
|
||||
|
||||
1. Add a new ID to `BeatTemplateId` in `src/domain/beatTemplates.ts`.
|
||||
2. Add a template to `BEAT_TEMPLATES` with label, description, meter, tempo, and points.
|
||||
3. Make sure every point has an instrument ID from `InstrumentId` and a step from zero up to, but not including, `beatsPerBar × STEPS_PER_BEAT`.
|
||||
4. Keep the template test passing or add a test for any special rule.
|
||||
|
||||
The selector reads its options from `BEAT_TEMPLATES`, so no separate menu option is needed.
|
||||
|
||||
### Change timing rules
|
||||
|
||||
Timing constants are in `src/domain/sequencer.ts`; circle conversion is in `src/domain/timeline.ts`; playback tick matching is in `src/hooks/useBeatPlayback.ts`. These parts must agree about subdivisions. If the number of playback subdivisions changes, review keyboard movement, point rounding, tick duration, tick drawing, and tests together.
|
||||
|
||||
## 9. Tests, configuration, and build output
|
||||
|
||||
`src/sequencer.test.ts` uses Vitest in the Node test environment. It covers:
|
||||
|
||||
- Converting between loop steps and circle coordinates.
|
||||
- Fractional steps, wrapping, and playback tick duration.
|
||||
- Finding a step for a new point.
|
||||
- Unique colors.
|
||||
- Reducer behavior for templates, deletion, meter changes, and tempo limits.
|
||||
- Template tempo and point bounds.
|
||||
|
||||
Run all project checks from the repository root:
|
||||
|
||||
```sh
|
||||
npm run lint
|
||||
npm run build
|
||||
npm test
|
||||
```
|
||||
|
||||
The scripts are defined in `package.json`. `npm run build` first runs TypeScript with no output, then Vite writes the app's static production site to `dist/`. The React plugin and Vitest environment are set in `vite.config.ts`. TypeScript strict options are in `tsconfig.json`; ESLint rules are in `eslint.config.js`.
|
||||
|
||||
The documentation site uses VitePress. Run `npm run docs:dev` to work on it locally, `npm run docs:build` to create its static files in `docs/.vitepress/dist/`, and `npm run docs:preview` to view that build. The pages are Markdown files under `docs/`; navigation and local search are set in `docs/.vitepress/config.mts`.
|
||||
|
||||
The project includes a web manifest and home-screen icons in `public/`, but it does not include a service worker, offline caching, persistence, a native mobile wrapper, or a server deployment configuration.
|
||||
|
||||
## 10. Main implementation limits
|
||||
|
||||
- A loop exists only in page memory. There is no save, load, or export feature.
|
||||
- The instrument catalog has 16 built-in synthesized instruments in seven categories.
|
||||
- Pitch controls are available only for instruments marked `supportsPitch`.
|
||||
- Playback timing uses a browser interval and may drift under load.
|
||||
- Points are rounded to one of four playback subdivisions per main step when they play.
|
||||
- The app makes audio with browser-generated oscillators and noise. It does not load user audio files.
|
||||
- The repository builds a static web app; native app packaging is not configured here.
|
||||
@@ -0,0 +1,220 @@
|
||||
# BeatHound Software Guide
|
||||
|
||||
This guide explains how to use BeatHound and how the software is put together. It uses short sentences and explains technical words when they first appear.
|
||||
|
||||
## 1. What BeatHound does
|
||||
|
||||
BeatHound is a beat-making tool that runs in a web browser. It shows one circular loop. You place sound points on the loop, move them, and play the pattern.
|
||||
|
||||
The instrument menu has Drums, Percussion, Bass, Keys, Strings, Winds, and Synth. It includes Kick, Snare, Hi-hat, Toms, Cymbals, Clap, Shaker, Cowbell, Woodblock, Bongos, Bass, Piano, Organ, Strings, Winds, and Synth. BeatHound creates these sounds in your browser; it does not load audio recordings.
|
||||
|
||||
The app needs no account or backend server. Your current loop lives in the open page. It is not saved when you refresh or close the page.
|
||||
|
||||
## 2. Use the beat maker
|
||||
|
||||
### Start a pattern
|
||||
|
||||
1. Open the Dance template menu near the top of the page.
|
||||
2. Choose a template, or choose **Empty** to clear the loop.
|
||||
3. Choose a category in the bottom toolbar, such as **Drums** or **Keys**.
|
||||
4. Press the **+** button beside the category menu to see its instruments.
|
||||
5. Choose an instrument. A point for it appears at an available place on the loop.
|
||||
|
||||
Adding the same instrument more than once adds more points of that instrument.
|
||||
|
||||
When you select a point for an instrument with pitch support, a pitch slider appears in the toolbar. It changes the selected point by up to two octaves in either direction. The note name follows that instrument's base note. Instruments such as Hi-hat, Snare, and Shaker do not have pitch controls.
|
||||
|
||||
### Move and select sound points
|
||||
|
||||
- Drag a point around its circle to change when it plays.
|
||||
- Click or tap a point to select it. Its sound ring is selected too.
|
||||
- You can also focus a point with the keyboard. Use the arrow keys to move it. Hold **Shift** with an arrow key to move by a larger step.
|
||||
- The rings are separate for each sound type. Click or tap a ring to select that sound. The ring selector at the top of the loop can also do this.
|
||||
- The colored legend below the loop shows which sounds are in the current pattern.
|
||||
|
||||
Use the trash button beside the loop to remove sound. If a point is selected, the button removes only that point. If a sound ring is selected and no point is selected, it removes every point of that sound.
|
||||
|
||||
### Change the loop and speed
|
||||
|
||||
- **Time signature** sets how many beats are in the loop. BeatHound offers 2/4 through 8/4.
|
||||
- **BPM** means beats per minute. Use the tempo menu to choose a speed from 60 to 180 BPM. The starting speed is 112 BPM.
|
||||
- **Play** starts the loop. Press **Pause** to stop it. Starting playback needs a sound in the loop.
|
||||
|
||||
The usual loop is 4/4. Each beat has four main steps, so a 4/4 loop has 16 main steps. The circular play marker shows where playback is.
|
||||
|
||||
Dragging allows small timing changes between main steps. The sound plays at the closest supported timing point. Keyboard arrow keys make small changes; **Shift** plus an arrow moves by one full main step.
|
||||
|
||||
If you shorten the loop, sound points outside the new loop length are hidden. They can appear again if you make the loop longer later.
|
||||
|
||||
### Included templates
|
||||
|
||||
Templates replace the current pattern and set its speed and time signature.
|
||||
|
||||
| Template | Loop | Speed | Pattern |
|
||||
| --- | --- | ---: | --- |
|
||||
| Empty | 4/4 | 112 BPM | No sound points |
|
||||
| Bachata | 4/4 | 120 BPM | Kick on beats 1, 2, 3, and 4 |
|
||||
| Salsa | 4/4 | 180 BPM | Kick on beats 1, 2, and 3 |
|
||||
| Lindy Hop | 8/4 | 120 BPM | Kick on beats 1 through 8 |
|
||||
|
||||
## 3. Sound and browser behavior
|
||||
|
||||
BeatHound uses the browser's **Web Audio API** to make sound. The Kick is made from low electronic tones. The Hi-hat is made from short filtered noise.
|
||||
|
||||
Browsers often block sound until the user interacts with the page. Press **Play** to allow the browser to start audio. If audio cannot start, BeatHound shows an error below the loop. Check the browser's audio settings and try again.
|
||||
|
||||
The app makes playback ticks with a browser timer. At each tick it checks whether a sound point should play. The exact timing can depend on the browser and the device.
|
||||
|
||||
The page layout adapts to different screen sizes. The project also includes a web app manifest, icons, and mobile home-screen metadata. This project does not include code for saving patterns, working offline, or building a native mobile app.
|
||||
|
||||
## 4. Run the project on your computer
|
||||
|
||||
### Requirements
|
||||
|
||||
- A recent Node.js release with npm.
|
||||
- A modern browser with Web Audio support to use the app.
|
||||
|
||||
### Install and run
|
||||
|
||||
From the project folder, run:
|
||||
|
||||
```sh
|
||||
npm install
|
||||
npm run dev
|
||||
```
|
||||
|
||||
Vite prints a local web address. Open that address in your browser. The dev server listens on all network interfaces, so it may also be reachable from another device on your local network.
|
||||
|
||||
### Checks and production build
|
||||
|
||||
```sh
|
||||
npm run lint
|
||||
npm run build
|
||||
npm test
|
||||
```
|
||||
|
||||
- `npm run lint` checks the source code with ESLint.
|
||||
- `npm run build` checks TypeScript and creates the production files in `dist/`.
|
||||
- `npm test` runs the tests with Vitest.
|
||||
|
||||
## 5. How the software is organized
|
||||
|
||||
BeatHound is a React and TypeScript app. Ionic React provides many of the buttons, popovers, and page elements. Vite runs the development server and builds the app.
|
||||
|
||||
The main path through the app is:
|
||||
|
||||
1. `index.html` provides the page shell and mobile and sharing metadata.
|
||||
2. `src/main.tsx` loads Ionic styles and the app's styles, then starts React.
|
||||
3. `src/App.tsx` keeps the shared studio state and chooses which view is open.
|
||||
4. `src/views/StudioView.tsx` displays the beat maker. `src/views/AboutView.tsx` displays app information.
|
||||
5. Components display the loop, header menu, and controls.
|
||||
6. Hooks manage the loop state, sound colors, and playback.
|
||||
7. Domain files define beat data and calculate loop positions.
|
||||
8. Audio files create and play the sounds.
|
||||
|
||||
### Source folder guide
|
||||
|
||||
| Path | What it does |
|
||||
| --- | --- |
|
||||
| `src/App.tsx` | Holds shared studio state and selects the active view. |
|
||||
| `src/main.tsx` | Starts React and loads Ionic and app styles. |
|
||||
| `src/styles.css` | Defines the colors, layout, and responsive page styles. |
|
||||
| `src/components/AppHeader.tsx` | Shows the brand and the top-right menu for switching views. |
|
||||
| `src/views/StudioView.tsx` | Shows the beat-making studio. |
|
||||
| `src/views/AboutView.tsx` | Shows the version, license, technologies, source repository, and issue tracker. |
|
||||
| `src/views/viewTypes.ts` | Defines the names of the app's views. |
|
||||
| `src/config/projectInfo.ts` | Keeps version and project links in one place for the About view. |
|
||||
| `src/components/BeatLoopPanel.tsx` | Combines the circular loop, tempo, time signature, sound ring, hint, and delete button. |
|
||||
| `src/components/CircularTimeline.tsx` | Draws the loop, sound points, and playback marker. It handles pointer and keyboard movement. |
|
||||
| `src/components/TransportBar.tsx` | Shows Play/Pause, the instrument menu, and pitch control. |
|
||||
| `src/components/InstrumentSelector.tsx` | Selects an instrument category and shows its choices from the plus button. |
|
||||
| `src/components/PitchControl.tsx` | Changes pitch on a selected point when its instrument supports pitch. |
|
||||
| `src/components/BeatTemplateSelector.tsx` | Shows the template menu. |
|
||||
| `src/components/TempoControl.tsx` | Changes the speed. |
|
||||
| `src/components/TimeSignatureSelector.tsx` | Changes the number of beats in the loop. |
|
||||
| `src/components/SoundRingSelector.tsx` | Selects a sound ring. |
|
||||
| `src/components/BeatSelectionHint.tsx` | Shows the selected sound and point position. |
|
||||
| `src/hooks/useBeatStudio.ts` | Connects the sequencer and sound color palette. |
|
||||
| `src/hooks/useBeatSequencer.ts` | Gives the interface actions for adding, moving, selecting, and removing points. |
|
||||
| `src/hooks/useBeatPlayback.ts` | Starts and stops playback and moves the play marker. |
|
||||
| `src/hooks/useSoundPalette.ts` | Gives each active sound a color. |
|
||||
| `src/hooks/usePopoverDisclosure.ts` | Tracks whether an Ionic popover is open. |
|
||||
| `src/domain/sequencer.ts` | Defines beat data, loop sizes, tempo limits, and timing helpers. |
|
||||
| `src/domain/sequencerReducer.ts` | Applies changes to the sequencer state. |
|
||||
| `src/domain/timeline.ts` | Converts between loop positions and points on the circle. |
|
||||
| `src/domain/instruments.ts` | Lists instruments, categories, and pitch settings. |
|
||||
| `src/domain/sounds.ts` | Re-exports older sound names for compatibility. |
|
||||
| `src/domain/soundColors.ts` | Creates distinct colors for active sounds. |
|
||||
| `src/domain/beatTemplates.ts` | Defines the included templates. |
|
||||
| `src/audio/AudioEngine.ts` | Starts the browser audio context and sends sounds to it. |
|
||||
| `src/audio/instruments.ts` | Creates the synthesized instrument sounds. |
|
||||
| `src/audio/soundVoices.ts` | Connects each instrument ID to its sound-making function. |
|
||||
| `src/sequencer.test.ts` | Tests timing, loop geometry, state changes, colors, and templates. |
|
||||
| `public/` | Holds icons, logos, and the web app manifest. |
|
||||
|
||||
`src/sequencer.ts` is a small export file. It re-exports domain helpers and templates for use by tests and other files.
|
||||
|
||||
### Project setup files
|
||||
|
||||
| Path | What it does |
|
||||
| --- | --- |
|
||||
| `package.json` | Lists the packages used by the project and the npm commands. |
|
||||
| `package-lock.json` | Records exact package versions for repeatable installs. |
|
||||
| `vite.config.ts` | Turns on the React plugin and sets up Vitest. |
|
||||
| `tsconfig.json` | Sets TypeScript rules. The project uses strict type checking. |
|
||||
| `eslint.config.js` | Sets the code checks used by ESLint. |
|
||||
| `.gitignore` | Keeps generated files such as `dist/` and `node_modules/` out of Git. |
|
||||
| `public/manifest.webmanifest` | Gives the app a name, icons, colors, and home-screen display settings. |
|
||||
| `src/ionicons.d.ts` | Tells TypeScript which Ionicons names this app uses. |
|
||||
|
||||
## 6. How loop data works
|
||||
|
||||
Each sound point has three values:
|
||||
|
||||
- `id`: a unique name for that point.
|
||||
- `soundId`: the sound type, such as `kick` or `hi-hat`.
|
||||
- `step`: its position in the loop. Whole numbers are main steps. Fractions allow small timing changes.
|
||||
- `pitchSemitones`: an optional pitch offset for instruments that support pitch.
|
||||
|
||||
The sequencer state also tracks the selected point, selected sound ring, tempo, and beats per bar. `src/domain/sequencerReducer.ts` receives named actions and returns the next state. This keeps changes in one predictable place.
|
||||
|
||||
The loop size is four main steps per beat. For example, 4/4 has 16 main steps and 8/4 has 32. Playback checks four smaller timing points within each main step.
|
||||
|
||||
The loop is held in React state. There is no database, network API, or browser storage in this version.
|
||||
|
||||
## 7. Add another sound
|
||||
|
||||
To add an instrument, update these files:
|
||||
|
||||
1. Add its ID, label, category, and pitch support to `src/domain/instruments.ts`.
|
||||
2. Add its ID to the correct category list in that file.
|
||||
3. Write a function that uses `AudioContext` in `src/audio/instruments.ts`.
|
||||
4. Add its instrument ID and function to `src/audio/soundVoices.ts`.
|
||||
|
||||
The toolbar menu reads its groups from the instrument catalog, and the color hook assigns a color when an instrument is added. The timeline uses the instrument ID, so it usually does not need an instrument-specific change.
|
||||
|
||||
## 8. Add another template
|
||||
|
||||
Add a template object to `BEAT_TEMPLATES` in `src/domain/beatTemplates.ts`. Include:
|
||||
|
||||
- A unique ID and a label.
|
||||
- A short description.
|
||||
- The number of beats per bar.
|
||||
- A tempo from 60 to 180 BPM.
|
||||
- Sound points whose steps fit inside that loop.
|
||||
|
||||
Also add the new ID to the `BeatTemplateId` type in that file. The menu reads its options from `BEAT_TEMPLATES`.
|
||||
|
||||
## 9. Tests and quality checks
|
||||
|
||||
The tests in `src/sequencer.test.ts` check the logic that can be tested without a browser. They check circular positions, fractional positions, tempo limits, state changes, colors, and templates.
|
||||
|
||||
Before sharing a change, run:
|
||||
|
||||
```sh
|
||||
npm run lint
|
||||
npm run build
|
||||
npm test
|
||||
```
|
||||
|
||||
If you change behavior, update or add a test for that behavior.
|
||||
Reference in new issue
Block a user