Add category rings and beat labels
This commit is contained in:
1 parent
9d8f277971
commit
4f221ea122
21 files changed
+752
-339
No files matched your search
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user