Add category rings and beat labels

This commit is contained in:
Ninosaurier committed 2026-11-15 14:35:36 +01:00
1 parent 9d8f277971
commit 4f221ea122
21 files changed
+752 -339

No files matched your search

+33 -22
View File
@@ -34,14 +34,14 @@ Main tools:
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
### Add an instrument 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.
5. The `beat-added` action updates reducer state. The new point becomes selected, and its category ring becomes focused.
6. React renders the new point and updates the category 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.
@@ -50,13 +50,13 @@ Most components do not own the loop data. The sequencer hook owns that data and
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.
4. Playback position is reset. The palette activates each category 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
### Beat point
The `BeatPoint` interface in `src/domain/sequencer.ts` is the data for one point:
@@ -64,6 +64,7 @@ The `BeatPoint` interface in `src/domain/sequencer.ts` is the data for one point
| --- | --- | --- |
| `id` | `string` | Unique ID for this point. |
| `soundId` | `InstrumentId` | Instrument type, such as `kick`, `piano`, or `shaker`. |
| `letter` | `string` | Lowercase marker label. It is unique within the beat's category. |
| `step` | `number` | Position in the loop. It can be a whole or fractional number. |
| `pitchSemitones` | `number?` | Optional pitch offset for instruments that support pitch. |
@@ -75,13 +76,13 @@ The instrument ID type comes from the keys in `src/domain/instruments.ts`. Addin
| Field | Meaning |
| --- | --- |
| `beats` | All sound points in the current loop. |
| `beats` | All beat points in the current loop. |
| `selectedBeatId` | ID of the point selected for moving or deleting, or `null`. |
| `focusedSoundId` | Sound ring currently selected, or `null`. |
| `focusedCategoryId` | Category 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.
Playback status and the play marker are kept separately by `useBeatPlayback`. Category colors are kept by `useSoundPalette`; renamed category labels are kept by `useCategoryLabels`. This separates musical data from playback and display details.
### Reducer actions
@@ -89,10 +90,10 @@ Playback status and the play marker are kept separately by `useBeatPlayback`. So
Important state rules:
- Selecting a point also focuses that point's sound ring.
- Selecting a ring clears the selected point.
- Selecting a point also focuses that point's category ring.
- Selecting a category ring clears the selected point.
- Removing a selected point removes only that point.
- Removing a focused ring removes every point of that sound type.
- Removing a focused ring removes every beat in that category.
- 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.
@@ -116,6 +117,8 @@ The constants and calculations are in `src/domain/sequencer.ts`:
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.
Each category has a fixed uppercase ring letter from A to G. Each beat gets the next available lowercase letter within its category (`a`–`z`, then `aa`, `ab`, and so on). Together they identify a beat, for example `A-a`. Templates receive these labels when loaded too.
`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
@@ -135,8 +138,10 @@ At 120 BPM, one playback tick is 31.25 milliseconds. Playback uses `window.setIn
- `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.
- `getCategoryOrbitRadius()` gives each active category its own circle.
- `getStackedPosition()` moves beats from the same category 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 category letter is drawn beside its circle. The beat's lowercase letter is drawn inside its point marker. The legend lists each category and maps beat letters to instrument names.
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.
@@ -186,16 +191,17 @@ The app uses a JavaScript interval to decide when to play sounds. Browser schedu
| `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. |
| `BeatLoopPanel` | Connects timeline, meter, tempo, category rings, legend, 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. |
| `CategoryRingSelector` | Selects an active category ring. |
| `CategoryLegend` | Shows category letters and beat-letter mappings; long press opens the rename dialog. |
| `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. |
| `BeatSelectionHint` | Shows the selected beat's category, letter, instrument, and position. |
### Hooks
@@ -204,7 +210,8 @@ The app uses a JavaScript interval to decide when to play sounds. Browser schedu
| `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. |
| `useSoundPalette` | Assigns one stable color to each instrument category activated in the current page session. |
| `useCategoryLabels` | Stores category legend names for 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.
@@ -217,14 +224,16 @@ Components are mostly presentational: they receive state and callbacks through p
`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.
- Pointer-down on a beat 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.
- Enter or Space on a category orbit selects that category ring.
- Each beat point displays its lowercase letter. The uppercase category letter is shown on the matching orbit.
- Press and hold a category in the legend to rename its displayed label. The category letter and beat letters do not change.
- 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.
The selection state is used by the trash button to decide whether to delete one point or all beats on the focused category ring.
## 8. Extend the software
@@ -258,8 +267,10 @@ Timing constants are in `src/domain/sequencer.ts`; circle conversion is in `src/
- 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.
- Category and beat-letter assignment, including alphabetic labels after Z.
- Visual stacking for same-category beats on the same playback tick.
- Unique category colors.
- Reducer behavior for templates, category deletion, meter changes, pitch, and tempo limits.
- Template tempo and point bounds.
Run all project checks from the repository root:
+18 -13
View File
@@ -27,12 +27,13 @@ When you select a point for an instrument with pitch support, a pitch slider app
### 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.
- Click or tap a point to select it. Its category 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.
- Instruments in the same category share one ring. Each ring has an uppercase letter, from **A** to **G**. Each beat has its own lowercase letter inside the ring. For example, **A-a** means beat `a` in category `A`.
- The legend below the loop connects category letters and beat letters to their names. Press and hold a category in the legend to rename it for the current page session.
- Click or tap a ring or use the category-ring selector above the loop to focus a category.
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.
Use the trash button beside the loop to remove sound. If a point is selected, the button removes only that beat. If a category ring is selected and no point is selected, it removes every beat in that category.
### Change the loop and speed
@@ -124,27 +125,30 @@ The main path through the app is:
| `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/BeatLoopPanel.tsx` | Combines the circular loop, tempo, time signature, category rings, hint, legend, and delete button. |
| `src/components/CircularTimeline.tsx` | Draws category rings, labeled beat points, and the playback marker. It handles pointer and keyboard movement. |
| `src/components/CategoryRingSelector.tsx` | Selects one of the active category rings. |
| `src/components/CategoryLegend.tsx` | Maps category and beat letters to instrument names; a long press opens the rename dialog. |
| `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/components/SoundRingSelector.tsx` | Compatibility export for the category ring selector. |
| `src/components/BeatSelectionHint.tsx` | Shows the selected category, beat letter, instrument, and 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/useSoundPalette.ts` | Gives each active category a color. |
| `src/hooks/useCategoryLabels.ts` | Stores custom legend names for the current page session. |
| `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/soundColors.ts` | Creates distinct colors for active categories. |
| `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. |
@@ -169,14 +173,15 @@ The main path through the app is:
## 6. How loop data works
Each sound point has three values:
Each beat point has these values:
- `id`: a unique name for that point.
- `soundId`: the sound type, such as `kick` or `hi-hat`.
- `soundId`: the instrument type, such as `kick` or `hi-hat`.
- `letter`: its lowercase label inside the category ring. Labels are unique within a category.
- `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 sequencer state also tracks the selected point, selected category 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.