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
@@ -1,6 +1,6 @@
|
|||||||
# BeatHound
|
# BeatHound
|
||||||
|
|
||||||
BeatHound is a small, mobile-friendly beat maker. Choose instruments by category, place them on a circular timeline, adjust pitch where supported, and play the loop in your browser.
|
BeatHound is a small, mobile-friendly beat maker. Place beats on labeled category rings, identify them by letter, rename legend categories with a long press, adjust pitch where supported, and play the loop in your browser.
|
||||||
|
|
||||||
## Start here
|
## Start here
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
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.
|
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.
|
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()`.
|
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.
|
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.
|
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 legend. If the instrument supports pitch, the toolbar also shows its pitch control.
|
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.
|
`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`.
|
1. `BeatTemplateSelector` reads the menu entries from `BEAT_TEMPLATES`.
|
||||||
2. Selecting an entry calls `useBeatStudio.applyTemplate()`.
|
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.
|
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.
|
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
|
## 3. Core data and state
|
||||||
|
|
||||||
### Sound point
|
### Beat point
|
||||||
|
|
||||||
The `BeatPoint` interface in `src/domain/sequencer.ts` is the data for one 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. |
|
| `id` | `string` | Unique ID for this point. |
|
||||||
| `soundId` | `InstrumentId` | Instrument type, such as `kick`, `piano`, or `shaker`. |
|
| `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. |
|
| `step` | `number` | Position in the loop. It can be a whole or fractional number. |
|
||||||
| `pitchSemitones` | `number?` | Optional pitch offset for instruments that support pitch. |
|
| `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 |
|
| 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`. |
|
| `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. |
|
| `tempoBpm` | Playback speed in beats per minute. |
|
||||||
| `beatsPerBar` | Number of beats in the loop. |
|
| `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
|
### Reducer actions
|
||||||
|
|
||||||
@@ -89,10 +90,10 @@ Playback status and the play marker are kept separately by `useBeatPlayback`. So
|
|||||||
|
|
||||||
Important state rules:
|
Important state rules:
|
||||||
|
|
||||||
- Selecting a point also focuses that point's sound ring.
|
- Selecting a point also focuses that point's category ring.
|
||||||
- Selecting a ring clears the selected point.
|
- Selecting a category ring clears the selected point.
|
||||||
- Removing a selected point removes only that 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.
|
- 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.
|
- 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.
|
- 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.
|
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.
|
`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
|
### 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.
|
- `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.
|
- `getStepFromPosition()` converts pointer coordinates back to a step.
|
||||||
- `wrapStepPosition()` keeps keyboard movement inside the loop.
|
- `wrapStepPosition()` keeps keyboard movement inside the loop.
|
||||||
- `getSoundOrbitRadius()` gives each sound its own circle.
|
- `getCategoryOrbitRadius()` gives each active category 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.
|
- `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.
|
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. |
|
| `AppHeader` | Shows the brand and opens the view menu with the Ionic `ellipsisVertical` icon. |
|
||||||
| `StudioView` | Displays the beat loop and template controls. |
|
| `StudioView` | Displays the beat loop and template controls. |
|
||||||
| `AboutView` | Displays project version, license, technology stack, repository, and issue tracker links. |
|
| `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. |
|
| `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. |
|
| `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. |
|
| `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. |
|
| `TransportBar` | Starts/stops playback and holds the instrument selector and pitch control. |
|
||||||
| `BeatTemplateSelector` | Displays and selects templates. |
|
| `BeatTemplateSelector` | Displays and selects templates. |
|
||||||
| `TempoControl` | Displays and changes tempo using an Ionic range. |
|
| `TempoControl` | Displays and changes tempo using an Ionic range. |
|
||||||
| `TimeSignatureSelector` | Displays and changes beats per bar. |
|
| `TimeSignatureSelector` | Displays and changes beats per bar. |
|
||||||
| `SoundRingSelector` | Selects one of the sound rings. |
|
| `BeatSelectionHint` | Shows the selected beat's category, letter, instrument, and position. |
|
||||||
| `BeatSelectionHint` | Shows the selected point position or selected sound ring. |
|
|
||||||
|
|
||||||
### Hooks
|
### 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. |
|
| `useBeatStudio` | Joins sequencer actions with sound palette activation. |
|
||||||
| `useBeatSequencer` | Owns reducer state and exposes typed sequencer operations to components. |
|
| `useBeatSequencer` | Owns reducer state and exposes typed sequencer operations to components. |
|
||||||
| `useBeatPlayback` | Owns audio startup, tick timer, play marker, and playback errors. |
|
| `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. |
|
| `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.
|
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.
|
`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.
|
- 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.
|
- 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.
|
- 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.
|
- 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
|
## 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.
|
- Converting between loop steps and circle coordinates.
|
||||||
- Fractional steps, wrapping, and playback tick duration.
|
- Fractional steps, wrapping, and playback tick duration.
|
||||||
- Finding a step for a new point.
|
- Finding a step for a new point.
|
||||||
- Unique colors.
|
- Category and beat-letter assignment, including alphabetic labels after Z.
|
||||||
- Reducer behavior for templates, deletion, meter changes, and tempo limits.
|
- 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.
|
- Template tempo and point bounds.
|
||||||
|
|
||||||
Run all project checks from the repository root:
|
Run all project checks from the repository root:
|
||||||
|
|||||||
+18
-13
@@ -27,12 +27,13 @@ When you select a point for an instrument with pitch support, a pitch slider app
|
|||||||
### Move and select sound points
|
### Move and select sound points
|
||||||
|
|
||||||
- Drag a point around its circle to change when it plays.
|
- 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.
|
- 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.
|
- 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 colored legend below the loop shows which sounds are in the current pattern.
|
- 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
|
### 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/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/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/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/BeatLoopPanel.tsx` | Combines the circular loop, tempo, time signature, category rings, hint, legend, and delete button. |
|
||||||
| `src/components/CircularTimeline.tsx` | Draws the loop, sound points, and playback marker. It handles pointer and keyboard movement. |
|
| `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/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/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/PitchControl.tsx` | Changes pitch on a selected point when its instrument supports pitch. |
|
||||||
| `src/components/BeatTemplateSelector.tsx` | Shows the template menu. |
|
| `src/components/BeatTemplateSelector.tsx` | Shows the template menu. |
|
||||||
| `src/components/TempoControl.tsx` | Changes the speed. |
|
| `src/components/TempoControl.tsx` | Changes the speed. |
|
||||||
| `src/components/TimeSignatureSelector.tsx` | Changes the number of beats in the loop. |
|
| `src/components/TimeSignatureSelector.tsx` | Changes the number of beats in the loop. |
|
||||||
| `src/components/SoundRingSelector.tsx` | Selects a sound ring. |
|
| `src/components/SoundRingSelector.tsx` | Compatibility export for the category ring selector. |
|
||||||
| `src/components/BeatSelectionHint.tsx` | Shows the selected sound and point position. |
|
| `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/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/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/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/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/sequencer.ts` | Defines beat data, loop sizes, tempo limits, and timing helpers. |
|
||||||
| `src/domain/sequencerReducer.ts` | Applies changes to the sequencer state. |
|
| `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/timeline.ts` | Converts between loop positions and points on the circle. |
|
||||||
| `src/domain/instruments.ts` | Lists instruments, categories, and pitch settings. |
|
| `src/domain/instruments.ts` | Lists instruments, categories, and pitch settings. |
|
||||||
| `src/domain/sounds.ts` | Re-exports older sound names for compatibility. |
|
| `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/domain/beatTemplates.ts` | Defines the included templates. |
|
||||||
| `src/audio/AudioEngine.ts` | Starts the browser audio context and sends sounds to it. |
|
| `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/instruments.ts` | Creates the synthesized instrument sounds. |
|
||||||
@@ -169,14 +173,15 @@ The main path through the app is:
|
|||||||
|
|
||||||
## 6. How loop data works
|
## 6. How loop data works
|
||||||
|
|
||||||
Each sound point has three values:
|
Each beat point has these values:
|
||||||
|
|
||||||
- `id`: a unique name for that point.
|
- `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.
|
- `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.
|
- `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.
|
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.
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ export function AppHeader({ activeView, onNavigate }: AppHeaderProps) {
|
|||||||
</a>
|
</a>
|
||||||
|
|
||||||
<div className="app-header-actions">
|
<div className="app-header-actions">
|
||||||
<span className="header-tag">Sharpen your sense of rhythm</span>
|
|
||||||
<IonButton
|
<IonButton
|
||||||
id="app-menu-trigger"
|
id="app-menu-trigger"
|
||||||
className="app-menu-trigger"
|
className="app-menu-trigger"
|
||||||
|
|||||||
@@ -2,39 +2,45 @@ import { useMemo } from 'react';
|
|||||||
import { IonButton, IonIcon } from '@ionic/react';
|
import { IonButton, IonIcon } from '@ionic/react';
|
||||||
import { trash } from 'ionicons/icons';
|
import { trash } from 'ionicons/icons';
|
||||||
import { BeatSelectionHint } from './BeatSelectionHint';
|
import { BeatSelectionHint } from './BeatSelectionHint';
|
||||||
|
import { CategoryLegend } from './CategoryLegend';
|
||||||
|
import { CategoryRingSelector } from './CategoryRingSelector';
|
||||||
import { CircularTimeline } from './CircularTimeline';
|
import { CircularTimeline } from './CircularTimeline';
|
||||||
import { SoundRingSelector } from './SoundRingSelector';
|
|
||||||
import { TempoControl } from './TempoControl';
|
import { TempoControl } from './TempoControl';
|
||||||
import { TimeSignatureSelector } from './TimeSignatureSelector';
|
import { TimeSignatureSelector } from './TimeSignatureSelector';
|
||||||
import { INSTRUMENT_BY_ID, INSTRUMENT_CATALOG } from '../domain/instruments';
|
import {
|
||||||
|
INSTRUMENT_BY_ID,
|
||||||
|
INSTRUMENT_CATEGORIES,
|
||||||
|
INSTRUMENT_CATEGORY_BY_ID,
|
||||||
|
} from '../domain/instruments';
|
||||||
|
import type { InstrumentCategoryId } from '../domain/instruments';
|
||||||
import type { BeatSequencer } from '../hooks/useBeatSequencer';
|
import type { BeatSequencer } from '../hooks/useBeatSequencer';
|
||||||
import type { SoundPalette } from '../hooks/useSoundPalette';
|
import type { SoundPalette } from '../hooks/useSoundPalette';
|
||||||
|
import type { CategoryLabels } from '../hooks/useCategoryLabels';
|
||||||
|
|
||||||
interface BeatLoopPanelProps {
|
interface BeatLoopPanelProps {
|
||||||
sequencer: BeatSequencer;
|
sequencer: BeatSequencer;
|
||||||
soundPalette: SoundPalette;
|
soundPalette: SoundPalette;
|
||||||
|
categoryLabels: CategoryLabels;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function BeatLoopPanel({ sequencer, soundPalette }: BeatLoopPanelProps) {
|
export function BeatLoopPanel({ sequencer, soundPalette, categoryLabels }: BeatLoopPanelProps) {
|
||||||
const soundIdsInLoop = useMemo(() => {
|
const categoryIdsInLoop = useMemo(() => {
|
||||||
const soundsInLoop = new Set(sequencer.beats.map((beat) => beat.soundId));
|
const categoryIds = new Set<InstrumentCategoryId>(
|
||||||
return INSTRUMENT_CATALOG
|
sequencer.beats.map((beat) => INSTRUMENT_BY_ID[beat.soundId].categoryId),
|
||||||
.filter((sound) => soundsInLoop.has(sound.id))
|
);
|
||||||
.map((sound) => sound.id);
|
return INSTRUMENT_CATEGORIES
|
||||||
|
.filter((category) => categoryIds.has(category.id))
|
||||||
|
.map((category) => category.id);
|
||||||
}, [sequencer.beats]);
|
}, [sequencer.beats]);
|
||||||
const legendSounds = useMemo(() => {
|
const focusedRingCategoryId = sequencer.focusedCategoryId
|
||||||
const soundsInLoop = new Set(soundIdsInLoop);
|
&& categoryIdsInLoop.includes(sequencer.focusedCategoryId)
|
||||||
return soundPalette.activeSounds.filter((sound) => soundsInLoop.has(sound.id));
|
? sequencer.focusedCategoryId
|
||||||
}, [soundPalette.activeSounds, soundIdsInLoop]);
|
|
||||||
const focusedRingSoundId = sequencer.focusedSoundId
|
|
||||||
&& soundIdsInLoop.includes(sequencer.focusedSoundId)
|
|
||||||
? sequencer.focusedSoundId
|
|
||||||
: null;
|
: null;
|
||||||
const hasDeleteTarget = Boolean(sequencer.selectedBeat || focusedRingSoundId);
|
const hasDeleteTarget = Boolean(sequencer.selectedBeat || focusedRingCategoryId);
|
||||||
const deleteLabel = sequencer.selectedBeat
|
const deleteLabel = sequencer.selectedBeat
|
||||||
? `Remove ${INSTRUMENT_BY_ID[sequencer.selectedBeat.soundId].label}`
|
? `Remove ${INSTRUMENT_BY_ID[sequencer.selectedBeat.soundId].label}`
|
||||||
: focusedRingSoundId
|
: focusedRingCategoryId
|
||||||
? `Remove ${INSTRUMENT_BY_ID[focusedRingSoundId].label} ring`
|
? `Remove ${categoryLabels.labelByCategoryId[focusedRingCategoryId] ?? INSTRUMENT_CATEGORY_BY_ID[focusedRingCategoryId].label} category`
|
||||||
: 'Remove sound';
|
: 'Remove sound';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -45,26 +51,28 @@ export function BeatLoopPanel({ sequencer, soundPalette }: BeatLoopPanelProps) {
|
|||||||
beatsPerBar={sequencer.beatsPerBar}
|
beatsPerBar={sequencer.beatsPerBar}
|
||||||
onChange={sequencer.setBeatsPerBar}
|
onChange={sequencer.setBeatsPerBar}
|
||||||
/>
|
/>
|
||||||
<SoundRingSelector
|
<CategoryRingSelector
|
||||||
soundIds={soundIdsInLoop}
|
categoryIds={categoryIdsInLoop}
|
||||||
focusedSoundId={sequencer.focusedSoundId}
|
focusedCategoryId={sequencer.focusedCategoryId}
|
||||||
colorBySoundId={soundPalette.colorBySoundId}
|
colorByCategoryId={soundPalette.colorByCategoryId}
|
||||||
onSelectSound={sequencer.selectSound}
|
labelByCategoryId={categoryLabels.labelByCategoryId}
|
||||||
|
onSelectCategory={sequencer.selectCategory}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="timeline-wrap">
|
<div className="timeline-wrap">
|
||||||
<CircularTimeline
|
<CircularTimeline
|
||||||
beats={sequencer.beats}
|
beats={sequencer.beats}
|
||||||
soundIds={soundIdsInLoop}
|
categoryIds={categoryIdsInLoop}
|
||||||
colorBySoundId={soundPalette.colorBySoundId}
|
colorByCategoryId={soundPalette.colorByCategoryId}
|
||||||
|
labelByCategoryId={categoryLabels.labelByCategoryId}
|
||||||
currentStep={sequencer.currentStep}
|
currentStep={sequencer.currentStep}
|
||||||
totalSteps={sequencer.totalSteps}
|
totalSteps={sequencer.totalSteps}
|
||||||
focusedSoundId={sequencer.focusedSoundId}
|
focusedCategoryId={sequencer.focusedCategoryId}
|
||||||
selectedBeatId={sequencer.selectedBeat?.id ?? null}
|
selectedBeatId={sequencer.selectedBeat?.id ?? null}
|
||||||
onMoveBeat={sequencer.moveBeat}
|
onMoveBeat={sequencer.moveBeat}
|
||||||
onSelectBeat={sequencer.selectBeat}
|
onSelectBeat={sequencer.selectBeat}
|
||||||
onSelectSound={sequencer.selectSound}
|
onSelectCategory={sequencer.selectCategory}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -77,8 +85,9 @@ export function BeatLoopPanel({ sequencer, soundPalette }: BeatLoopPanelProps) {
|
|||||||
</div>
|
</div>
|
||||||
<BeatSelectionHint
|
<BeatSelectionHint
|
||||||
selectedBeat={sequencer.selectedBeat}
|
selectedBeat={sequencer.selectedBeat}
|
||||||
focusedSoundId={focusedRingSoundId}
|
focusedCategoryId={focusedRingCategoryId}
|
||||||
colorBySoundId={soundPalette.colorBySoundId}
|
categoryLabelById={categoryLabels.labelByCategoryId}
|
||||||
|
colorByCategoryId={soundPalette.colorByCategoryId}
|
||||||
totalSteps={sequencer.totalSteps}
|
totalSteps={sequencer.totalSteps}
|
||||||
/>
|
/>
|
||||||
<div className="timeline-hint-actions">
|
<div className="timeline-hint-actions">
|
||||||
@@ -89,7 +98,7 @@ export function BeatLoopPanel({ sequencer, soundPalette }: BeatLoopPanelProps) {
|
|||||||
aria-label={deleteLabel}
|
aria-label={deleteLabel}
|
||||||
onClick={sequencer.selectedBeat
|
onClick={sequencer.selectedBeat
|
||||||
? sequencer.removeSelectedBeat
|
? sequencer.removeSelectedBeat
|
||||||
: sequencer.removeFocusedSound}
|
: sequencer.removeFocusedCategory}
|
||||||
>
|
>
|
||||||
<IonIcon icon={trash} />
|
<IonIcon icon={trash} />
|
||||||
</IonButton>
|
</IonButton>
|
||||||
@@ -100,18 +109,13 @@ export function BeatLoopPanel({ sequencer, soundPalette }: BeatLoopPanelProps) {
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div className="sound-legend" aria-label="Sounds in this loop" aria-live="polite">
|
<CategoryLegend
|
||||||
{legendSounds.length > 0 ? (
|
beats={sequencer.beats}
|
||||||
legendSounds.map((activeSound) => (
|
categoryIds={categoryIdsInLoop}
|
||||||
<span className="legend-sound" key={activeSound.id}>
|
colorByCategoryId={soundPalette.colorByCategoryId}
|
||||||
<span className="legend-swatch" style={{ backgroundColor: activeSound.color }} />
|
labelByCategoryId={categoryLabels.labelByCategoryId}
|
||||||
{INSTRUMENT_BY_ID[activeSound.id].label}
|
onRenameCategory={categoryLabels.renameCategory}
|
||||||
</span>
|
/>
|
||||||
))
|
|
||||||
) : (
|
|
||||||
<span className="legend-empty">Your added sounds will appear here.</span>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,34 +1,43 @@
|
|||||||
import { memo } from 'react';
|
import { memo } from 'react';
|
||||||
import { getLoopPositionPercent } from '../domain/timeline';
|
import { getLoopPositionPercent } from '../domain/timeline';
|
||||||
import { INSTRUMENT_BY_ID } from '../domain/instruments';
|
import { INSTRUMENT_BY_ID, INSTRUMENT_CATEGORY_BY_ID } from '../domain/instruments';
|
||||||
import type { BeatPoint } from '../domain/sequencer';
|
import type { BeatPoint } from '../domain/sequencer';
|
||||||
import type { InstrumentId } from '../domain/instruments';
|
import type { InstrumentCategoryId } from '../domain/instruments';
|
||||||
|
import type { CategoryLabelOverrides } from '../hooks/useCategoryLabels';
|
||||||
|
|
||||||
interface BeatSelectionHintProps {
|
interface BeatSelectionHintProps {
|
||||||
selectedBeat: BeatPoint | undefined;
|
selectedBeat: BeatPoint | undefined;
|
||||||
focusedSoundId: InstrumentId | null;
|
focusedCategoryId: InstrumentCategoryId | null;
|
||||||
colorBySoundId: Partial<Record<InstrumentId, string>>;
|
categoryLabelById: CategoryLabelOverrides;
|
||||||
|
colorByCategoryId: Partial<Record<InstrumentCategoryId, string>>;
|
||||||
totalSteps: number;
|
totalSteps: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BeatSelectionHint = memo(function BeatSelectionHint({
|
export const BeatSelectionHint = memo(function BeatSelectionHint({
|
||||||
selectedBeat,
|
selectedBeat,
|
||||||
focusedSoundId,
|
focusedCategoryId,
|
||||||
colorBySoundId,
|
categoryLabelById,
|
||||||
|
colorByCategoryId,
|
||||||
totalSteps,
|
totalSteps,
|
||||||
}: BeatSelectionHintProps) {
|
}: BeatSelectionHintProps) {
|
||||||
const soundId = selectedBeat?.soundId ?? focusedSoundId;
|
const selectedInstrument = selectedBeat ? INSTRUMENT_BY_ID[selectedBeat.soundId] : undefined;
|
||||||
if (!soundId) return <p className="timeline-hint" aria-live="polite" />;
|
const categoryId = selectedInstrument?.categoryId ?? focusedCategoryId;
|
||||||
|
if (!categoryId) return <p className="timeline-hint" aria-live="polite" />;
|
||||||
|
|
||||||
|
const category = INSTRUMENT_CATEGORY_BY_ID[categoryId];
|
||||||
|
const categoryLabel = categoryLabelById[categoryId] ?? category.label;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<p className="timeline-hint" aria-live="polite">
|
<p className="timeline-hint" aria-live="polite">
|
||||||
<span
|
<span
|
||||||
className="hint-swatch"
|
className="hint-swatch"
|
||||||
style={{ backgroundColor: colorBySoundId[soundId] }}
|
style={{ backgroundColor: colorByCategoryId[categoryId] }}
|
||||||
/>
|
/>
|
||||||
{INSTRUMENT_BY_ID[soundId].label}
|
{category.letter} · {categoryLabel}
|
||||||
{selectedBeat && (
|
{selectedBeat && (
|
||||||
<>
|
<>
|
||||||
|
<span className="hint-separator">·</span>
|
||||||
|
{selectedBeat.letter} · {selectedInstrument?.label}
|
||||||
<span className="hint-separator">·</span>
|
<span className="hint-separator">·</span>
|
||||||
Step {getLoopPositionPercent(selectedBeat.step, totalSteps)}% selected
|
Step {getLoopPositionPercent(selectedBeat.step, totalSteps)}% selected
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
import { useEffect, useRef, useState } from 'react';
|
||||||
|
import { IonAlert, IonButton } from '@ionic/react';
|
||||||
|
import { INSTRUMENT_BY_ID, INSTRUMENT_CATEGORY_BY_ID } from '../domain/instruments';
|
||||||
|
import type { InstrumentCategoryId } from '../domain/instruments';
|
||||||
|
import type { BeatPoint } from '../domain/sequencer';
|
||||||
|
import type { CategoryLabelOverrides } from '../hooks/useCategoryLabels';
|
||||||
|
|
||||||
|
interface CategoryLegendProps {
|
||||||
|
beats: readonly BeatPoint[];
|
||||||
|
categoryIds: readonly InstrumentCategoryId[];
|
||||||
|
colorByCategoryId: Partial<Record<InstrumentCategoryId, string>>;
|
||||||
|
labelByCategoryId: CategoryLabelOverrides;
|
||||||
|
onRenameCategory: (categoryId: InstrumentCategoryId, label: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CategoryLegend({
|
||||||
|
beats,
|
||||||
|
categoryIds,
|
||||||
|
colorByCategoryId,
|
||||||
|
labelByCategoryId,
|
||||||
|
onRenameCategory,
|
||||||
|
}: CategoryLegendProps) {
|
||||||
|
const [editingCategoryId, setEditingCategoryId] = useState<InstrumentCategoryId | null>(null);
|
||||||
|
const longPressTimerRef = useRef<number | null>(null);
|
||||||
|
const editingCategory = editingCategoryId
|
||||||
|
? INSTRUMENT_CATEGORY_BY_ID[editingCategoryId]
|
||||||
|
: undefined;
|
||||||
|
const editingLabel = editingCategory
|
||||||
|
? labelByCategoryId[editingCategory.id] ?? editingCategory.label
|
||||||
|
: '';
|
||||||
|
|
||||||
|
function clearLongPressTimer(): void {
|
||||||
|
if (longPressTimerRef.current === null) return;
|
||||||
|
window.clearTimeout(longPressTimerRef.current);
|
||||||
|
longPressTimerRef.current = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function beginRename(categoryId: InstrumentCategoryId): void {
|
||||||
|
clearLongPressTimer();
|
||||||
|
setEditingCategoryId(categoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveRename(value: unknown): void {
|
||||||
|
if (!editingCategoryId || typeof value !== 'object' || value === null) return;
|
||||||
|
const label = (value as Record<string, unknown>).categoryName;
|
||||||
|
if (typeof label === 'string') onRenameCategory(editingCategoryId, label);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => () => {
|
||||||
|
if (longPressTimerRef.current !== null) window.clearTimeout(longPressTimerRef.current);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="sound-legend" aria-label="Instrument categories in this loop" aria-live="polite">
|
||||||
|
{categoryIds.length > 0 ? (
|
||||||
|
categoryIds.map((categoryId) => {
|
||||||
|
const category = INSTRUMENT_CATEGORY_BY_ID[categoryId];
|
||||||
|
const label = labelByCategoryId[categoryId] ?? category.label;
|
||||||
|
const categoryBeats = beats.filter(
|
||||||
|
(beat) => INSTRUMENT_BY_ID[beat.soundId].categoryId === categoryId,
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<div className="legend-category-entry" key={categoryId}>
|
||||||
|
<IonButton
|
||||||
|
className="legend-category"
|
||||||
|
fill="clear"
|
||||||
|
aria-label={`Press and hold to rename ${label}`}
|
||||||
|
onPointerDown={() => {
|
||||||
|
clearLongPressTimer();
|
||||||
|
longPressTimerRef.current = window.setTimeout(
|
||||||
|
() => beginRename(categoryId),
|
||||||
|
550,
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
onPointerUp={clearLongPressTimer}
|
||||||
|
onPointerLeave={clearLongPressTimer}
|
||||||
|
onPointerCancel={clearLongPressTimer}
|
||||||
|
onContextMenu={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
beginRename(categoryId);
|
||||||
|
}}
|
||||||
|
onKeyDown={(event) => {
|
||||||
|
if (event.key !== 'Enter' && event.key !== ' ') return;
|
||||||
|
event.preventDefault();
|
||||||
|
beginRename(categoryId);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
className="legend-swatch"
|
||||||
|
style={{ backgroundColor: colorByCategoryId[categoryId] }}
|
||||||
|
/>
|
||||||
|
<span className="legend-category-letter">{category.letter}</span>
|
||||||
|
<span>{label}</span>
|
||||||
|
</IonButton>
|
||||||
|
<span className="legend-beat-list">
|
||||||
|
{categoryBeats.map((beat) => (
|
||||||
|
<span key={beat.id}>
|
||||||
|
<strong>{beat.letter}</strong> {INSTRUMENT_BY_ID[beat.soundId].label}
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<span className="legend-empty">Added instrument categories will appear here.</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<IonAlert
|
||||||
|
isOpen={editingCategory !== undefined}
|
||||||
|
header={`Rename ${editingLabel || 'category'}`}
|
||||||
|
message="This name is shown in the loop legend."
|
||||||
|
inputs={[{ name: 'categoryName', type: 'text', value: editingLabel, placeholder: 'Category name' }]}
|
||||||
|
buttons={[
|
||||||
|
{ text: 'Cancel', role: 'cancel' },
|
||||||
|
{ text: 'Save', handler: (value: unknown) => saveRename(value) },
|
||||||
|
]}
|
||||||
|
onDidDismiss={() => setEditingCategoryId(null)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import { memo } from 'react';
|
||||||
|
import { IonButton, IonIcon, IonPopover } from '@ionic/react';
|
||||||
|
import { chevronDown } from 'ionicons/icons';
|
||||||
|
import { INSTRUMENT_CATEGORY_BY_ID } from '../domain/instruments';
|
||||||
|
import type { InstrumentCategoryId } from '../domain/instruments';
|
||||||
|
import type { CategoryLabelOverrides } from '../hooks/useCategoryLabels';
|
||||||
|
import { usePopoverDisclosure } from '../hooks/usePopoverDisclosure';
|
||||||
|
|
||||||
|
interface CategoryRingSelectorProps {
|
||||||
|
categoryIds: readonly InstrumentCategoryId[];
|
||||||
|
focusedCategoryId: InstrumentCategoryId | null;
|
||||||
|
colorByCategoryId: Partial<Record<InstrumentCategoryId, string>>;
|
||||||
|
labelByCategoryId: CategoryLabelOverrides;
|
||||||
|
onSelectCategory: (categoryId: InstrumentCategoryId) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const CategoryRingSelector = memo(function CategoryRingSelector({
|
||||||
|
categoryIds,
|
||||||
|
focusedCategoryId,
|
||||||
|
colorByCategoryId,
|
||||||
|
labelByCategoryId,
|
||||||
|
onSelectCategory,
|
||||||
|
}: CategoryRingSelectorProps) {
|
||||||
|
const popover = usePopoverDisclosure();
|
||||||
|
const focusedCategory = focusedCategoryId
|
||||||
|
? INSTRUMENT_CATEGORY_BY_ID[focusedCategoryId]
|
||||||
|
: undefined;
|
||||||
|
const focusedLabel = focusedCategory
|
||||||
|
? labelByCategoryId[focusedCategory.id] ?? focusedCategory.label
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<IonButton
|
||||||
|
id="category-ring-selector-trigger"
|
||||||
|
className="sound-ring-selector-trigger"
|
||||||
|
fill="clear"
|
||||||
|
disabled={categoryIds.length === 0}
|
||||||
|
aria-label={focusedCategory ? `Selected ring: ${focusedLabel}` : 'Select a category ring'}
|
||||||
|
aria-haspopup="dialog"
|
||||||
|
aria-expanded={popover.isOpen}
|
||||||
|
>
|
||||||
|
<span className="sound-ring-trigger-content">
|
||||||
|
{focusedCategory && (
|
||||||
|
<>
|
||||||
|
<span
|
||||||
|
className="ring-selector-swatch"
|
||||||
|
style={{ backgroundColor: colorByCategoryId[focusedCategory.id] ?? '#b8b4e0' }}
|
||||||
|
/>
|
||||||
|
<span className="category-letter-badge">{focusedCategory.letter}</span>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<span>{focusedLabel ? `${focusedLabel} ring` : 'Category rings'}</span>
|
||||||
|
<IonIcon icon={chevronDown} />
|
||||||
|
</span>
|
||||||
|
</IonButton>
|
||||||
|
|
||||||
|
<IonPopover
|
||||||
|
className="sound-ring-popover"
|
||||||
|
trigger="category-ring-selector-trigger"
|
||||||
|
triggerAction="click"
|
||||||
|
side="bottom"
|
||||||
|
alignment="end"
|
||||||
|
dismissOnSelect
|
||||||
|
onDidPresent={popover.onDidPresent}
|
||||||
|
onDidDismiss={popover.onDidDismiss}
|
||||||
|
>
|
||||||
|
<div className="sound-ring-options" role="group" aria-label="Category rings">
|
||||||
|
{categoryIds.map((categoryId) => {
|
||||||
|
const category = INSTRUMENT_CATEGORY_BY_ID[categoryId];
|
||||||
|
const label = labelByCategoryId[categoryId] ?? category.label;
|
||||||
|
const selected = categoryId === focusedCategoryId;
|
||||||
|
return (
|
||||||
|
<IonButton
|
||||||
|
key={categoryId}
|
||||||
|
className="sound-ring-option"
|
||||||
|
fill={selected ? 'solid' : 'clear'}
|
||||||
|
aria-pressed={selected}
|
||||||
|
onClick={() => onSelectCategory(categoryId)}
|
||||||
|
>
|
||||||
|
<span className="sound-ring-option-content">
|
||||||
|
<span
|
||||||
|
className="ring-selector-swatch"
|
||||||
|
style={{ backgroundColor: colorByCategoryId[categoryId] ?? '#b8b4e0' }}
|
||||||
|
/>
|
||||||
|
<span className="category-letter-badge">{category.letter}</span>
|
||||||
|
<span>{label} ring</span>
|
||||||
|
</span>
|
||||||
|
</IonButton>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</IonPopover>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
});
|
||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
getPointForStep,
|
getPointForStep,
|
||||||
getLoopPositionPercent,
|
getLoopPositionPercent,
|
||||||
getSoundOrbitRadius,
|
getCategoryOrbitRadius,
|
||||||
getStepFromPosition,
|
getStepFromPosition,
|
||||||
ORBIT_RADIUS,
|
ORBIT_RADIUS,
|
||||||
SVG_CENTER,
|
SVG_CENTER,
|
||||||
@@ -16,20 +16,22 @@ import {
|
|||||||
getStackedPosition,
|
getStackedPosition,
|
||||||
wrapStepPosition,
|
wrapStepPosition,
|
||||||
} from '../domain/timeline';
|
} from '../domain/timeline';
|
||||||
import { INSTRUMENT_BY_ID } from '../domain/instruments';
|
import { INSTRUMENT_BY_ID, INSTRUMENT_CATEGORY_BY_ID } from '../domain/instruments';
|
||||||
import type { InstrumentId } from '../domain/instruments';
|
import type { InstrumentCategoryId } from '../domain/instruments';
|
||||||
|
import type { CategoryLabelOverrides } from '../hooks/useCategoryLabels';
|
||||||
|
|
||||||
interface CircularTimelineProps {
|
interface CircularTimelineProps {
|
||||||
beats: BeatPoint[];
|
beats: BeatPoint[];
|
||||||
soundIds: readonly InstrumentId[];
|
categoryIds: readonly InstrumentCategoryId[];
|
||||||
colorBySoundId: Partial<Record<InstrumentId, string>>;
|
colorByCategoryId: Partial<Record<InstrumentCategoryId, string>>;
|
||||||
|
labelByCategoryId: CategoryLabelOverrides;
|
||||||
currentStep: number;
|
currentStep: number;
|
||||||
totalSteps: number;
|
totalSteps: number;
|
||||||
focusedSoundId: InstrumentId | null;
|
focusedCategoryId: InstrumentCategoryId | null;
|
||||||
selectedBeatId: string | null;
|
selectedBeatId: string | null;
|
||||||
onMoveBeat: (beatId: string, step: number) => void;
|
onMoveBeat: (beatId: string, step: number) => void;
|
||||||
onSelectBeat: (beatId: string) => void;
|
onSelectBeat: (beatId: string) => void;
|
||||||
onSelectSound: (soundId: InstrumentId) => void;
|
onSelectCategory: (categoryId: InstrumentCategoryId) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPointerCoordinates(event: ReactPointerEvent<SVGSVGElement>) {
|
function getPointerCoordinates(event: ReactPointerEvent<SVGSVGElement>) {
|
||||||
@@ -42,25 +44,29 @@ function getPointerCoordinates(event: ReactPointerEvent<SVGSVGElement>) {
|
|||||||
|
|
||||||
export function CircularTimeline({
|
export function CircularTimeline({
|
||||||
beats,
|
beats,
|
||||||
soundIds,
|
categoryIds,
|
||||||
colorBySoundId,
|
colorByCategoryId,
|
||||||
|
labelByCategoryId,
|
||||||
currentStep,
|
currentStep,
|
||||||
totalSteps,
|
totalSteps,
|
||||||
focusedSoundId,
|
focusedCategoryId,
|
||||||
selectedBeatId,
|
selectedBeatId,
|
||||||
onMoveBeat,
|
onMoveBeat,
|
||||||
onSelectBeat,
|
onSelectBeat,
|
||||||
onSelectSound,
|
onSelectCategory,
|
||||||
}: CircularTimelineProps) {
|
}: CircularTimelineProps) {
|
||||||
const draggingBeatIdRef = useRef<string | null>(null);
|
const draggingBeatIdRef = useRef<string | null>(null);
|
||||||
const selectedBeatSoundId = beats.find((beat) => beat.id === selectedBeatId)?.soundId;
|
const selectedBeatSoundId = beats.find((beat) => beat.id === selectedBeatId)?.soundId;
|
||||||
const activeSoundId = selectedBeatSoundId ?? focusedSoundId;
|
const selectedBeatCategoryId = selectedBeatSoundId
|
||||||
const orderedSoundIds = activeSoundId
|
? INSTRUMENT_BY_ID[selectedBeatSoundId].categoryId
|
||||||
|
: null;
|
||||||
|
const activeCategoryId = selectedBeatCategoryId ?? focusedCategoryId;
|
||||||
|
const orderedCategoryIds = activeCategoryId
|
||||||
? [
|
? [
|
||||||
...soundIds.filter((soundId) => soundId === activeSoundId),
|
...categoryIds.filter((categoryId) => categoryId === activeCategoryId),
|
||||||
...soundIds.filter((soundId) => soundId !== activeSoundId),
|
...categoryIds.filter((categoryId) => categoryId !== activeCategoryId),
|
||||||
]
|
]
|
||||||
: soundIds;
|
: categoryIds;
|
||||||
|
|
||||||
function handlePointerDown(event: ReactPointerEvent<SVGGElement>, beatId: string): void {
|
function handlePointerDown(event: ReactPointerEvent<SVGGElement>, beatId: string): void {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -96,11 +102,11 @@ export function CircularTimeline({
|
|||||||
|
|
||||||
function handleOrbitKeyDown(
|
function handleOrbitKeyDown(
|
||||||
event: ReactKeyboardEvent<SVGCircleElement>,
|
event: ReactKeyboardEvent<SVGCircleElement>,
|
||||||
soundId: InstrumentId,
|
categoryId: InstrumentCategoryId,
|
||||||
): void {
|
): void {
|
||||||
if (event.key !== 'Enter' && event.key !== ' ') return;
|
if (event.key !== 'Enter' && event.key !== ' ') return;
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
onSelectSound(soundId);
|
onSelectCategory(categoryId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -108,25 +114,44 @@ export function CircularTimeline({
|
|||||||
className="circular-timeline"
|
className="circular-timeline"
|
||||||
viewBox={`0 0 ${SVG_SIZE} ${SVG_SIZE}`}
|
viewBox={`0 0 ${SVG_SIZE} ${SVG_SIZE}`}
|
||||||
role="group"
|
role="group"
|
||||||
aria-label={`${totalSteps}-step circular beat timeline with a separate orbit per sound. Drag sound points to move them.`}
|
aria-label={`${totalSteps}-step circular beat timeline with one orbit per instrument category. Drag beat points to move them.`}
|
||||||
onPointerMove={handlePointerMove}
|
onPointerMove={handlePointerMove}
|
||||||
onPointerUp={() => { draggingBeatIdRef.current = null; }}
|
onPointerUp={() => { draggingBeatIdRef.current = null; }}
|
||||||
onPointerCancel={() => { draggingBeatIdRef.current = null; }}
|
onPointerCancel={() => { draggingBeatIdRef.current = null; }}
|
||||||
>
|
>
|
||||||
{orderedSoundIds.map((soundId, soundIndex) => (
|
{orderedCategoryIds.map((categoryId, categoryIndex) => {
|
||||||
<circle
|
const category = INSTRUMENT_CATEGORY_BY_ID[categoryId];
|
||||||
key={soundId}
|
const color = colorByCategoryId[categoryId] ?? '#b8b4e0';
|
||||||
cx={SVG_CENTER}
|
const radius = getCategoryOrbitRadius(categoryIndex, orderedCategoryIds.length);
|
||||||
cy={SVG_CENTER}
|
const letterPosition = getPointForStep(totalSteps * 0.12, radius, SVG_CENTER, totalSteps);
|
||||||
r={getSoundOrbitRadius(soundIndex, orderedSoundIds.length)}
|
const focused = categoryId === activeCategoryId;
|
||||||
className={`timeline-orbit${soundId === activeSoundId ? ' is-focused' : ''}`}
|
return (
|
||||||
style={{
|
<g key={categoryId}>
|
||||||
stroke: colorBySoundId[soundId] ?? '#b8b4e0',
|
<circle
|
||||||
opacity: soundId === activeSoundId ? 0.55 : 0.32,
|
cx={SVG_CENTER}
|
||||||
strokeWidth: soundId === activeSoundId ? 2.2 : 1.5,
|
cy={SVG_CENTER}
|
||||||
}}
|
r={radius}
|
||||||
/>
|
className={`timeline-orbit${focused ? ' is-focused' : ''}`}
|
||||||
))}
|
style={{
|
||||||
|
stroke: color,
|
||||||
|
opacity: focused ? 0.55 : 0.32,
|
||||||
|
strokeWidth: focused ? 2.2 : 1.5,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<g className="timeline-category-letter" style={{ color }} aria-hidden="true">
|
||||||
|
<circle cx={letterPosition.x} cy={letterPosition.y} r="9" />
|
||||||
|
<text
|
||||||
|
x={letterPosition.x}
|
||||||
|
y={letterPosition.y}
|
||||||
|
textAnchor="middle"
|
||||||
|
dominantBaseline="middle"
|
||||||
|
>
|
||||||
|
{category.letter}
|
||||||
|
</text>
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
{Array.from({ length: totalSteps * PLAYBACK_SUBSTEPS_PER_STEP }, (_, tick) => {
|
{Array.from({ length: totalSteps * PLAYBACK_SUBSTEPS_PER_STEP }, (_, tick) => {
|
||||||
const step = tick / PLAYBACK_SUBSTEPS_PER_STEP;
|
const step = tick / PLAYBACK_SUBSTEPS_PER_STEP;
|
||||||
@@ -155,12 +180,12 @@ export function CircularTimeline({
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
{orderedSoundIds.map((soundId, soundIndex) => (
|
{orderedCategoryIds.map((categoryId, categoryIndex) => (
|
||||||
<circle
|
<circle
|
||||||
key={soundId}
|
key={categoryId}
|
||||||
cx={SVG_CENTER}
|
cx={SVG_CENTER}
|
||||||
cy={SVG_CENTER}
|
cy={SVG_CENTER}
|
||||||
r={getSoundOrbitRadius(soundIndex, orderedSoundIds.length)}
|
r={getCategoryOrbitRadius(categoryIndex, orderedCategoryIds.length)}
|
||||||
className="timeline-orbit-hit-area"
|
className="timeline-orbit-hit-area"
|
||||||
fill="none"
|
fill="none"
|
||||||
stroke="transparent"
|
stroke="transparent"
|
||||||
@@ -168,11 +193,11 @@ export function CircularTimeline({
|
|||||||
pointerEvents="stroke"
|
pointerEvents="stroke"
|
||||||
role="button"
|
role="button"
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
aria-label={`Select ${INSTRUMENT_BY_ID[soundId].label} ring`}
|
aria-label={`Select ${INSTRUMENT_CATEGORY_BY_ID[categoryId].letter} ${labelByCategoryId[categoryId] ?? INSTRUMENT_CATEGORY_BY_ID[categoryId].label} ring`}
|
||||||
aria-pressed={soundId === activeSoundId}
|
aria-pressed={categoryId === activeCategoryId}
|
||||||
onClick={() => onSelectSound(soundId)}
|
onClick={() => onSelectCategory(categoryId)}
|
||||||
onKeyDown={(event) => handleOrbitKeyDown(event, soundId)}
|
onKeyDown={(event) => handleOrbitKeyDown(event, categoryId)}
|
||||||
onFocus={() => onSelectSound(soundId)}
|
onFocus={() => onSelectCategory(categoryId)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
@@ -187,23 +212,24 @@ export function CircularTimeline({
|
|||||||
})()}
|
})()}
|
||||||
|
|
||||||
{beats.map((beat) => {
|
{beats.map((beat) => {
|
||||||
const sound = INSTRUMENT_BY_ID[beat.soundId];
|
const instrument = INSTRUMENT_BY_ID[beat.soundId];
|
||||||
const soundIndex = orderedSoundIds.indexOf(beat.soundId);
|
const category = INSTRUMENT_CATEGORY_BY_ID[instrument.categoryId];
|
||||||
|
const categoryIndex = orderedCategoryIds.indexOf(instrument.categoryId);
|
||||||
const point = getStackedPosition(
|
const point = getStackedPosition(
|
||||||
beat,
|
beat,
|
||||||
beats,
|
beats,
|
||||||
totalSteps,
|
totalSteps,
|
||||||
getSoundOrbitRadius(soundIndex, orderedSoundIds.length),
|
getCategoryOrbitRadius(categoryIndex, orderedCategoryIds.length),
|
||||||
);
|
);
|
||||||
const selected = selectedBeatId === beat.id;
|
const selected = selectedBeatId === beat.id;
|
||||||
return (
|
return (
|
||||||
<g
|
<g
|
||||||
key={beat.id}
|
key={beat.id}
|
||||||
className={`sound-point${selected ? ' is-selected' : ''}`}
|
className={`sound-point${selected ? ' is-selected' : ''}`}
|
||||||
style={{ color: colorBySoundId[beat.soundId] ?? '#f4f1ed' }}
|
style={{ color: colorByCategoryId[instrument.categoryId] ?? '#f4f1ed' }}
|
||||||
role="button"
|
role="button"
|
||||||
tabIndex={0}
|
tabIndex={0}
|
||||||
aria-label={`${sound.label}, ${getLoopPositionPercent(beat.step, totalSteps)}% around the loop. Drag to move freely, or use arrow keys for small steps.`}
|
aria-label={`${category.letter} ${labelByCategoryId[category.id] ?? category.label}, beat ${beat.letter}, ${instrument.label}, ${getLoopPositionPercent(beat.step, totalSteps)}% around the loop. Drag to move freely, or use arrow keys for small steps.`}
|
||||||
aria-pressed={selected}
|
aria-pressed={selected}
|
||||||
onPointerDown={(event) => handlePointerDown(event, beat.id)}
|
onPointerDown={(event) => handlePointerDown(event, beat.id)}
|
||||||
onClick={() => onSelectBeat(beat.id)}
|
onClick={() => onSelectBeat(beat.id)}
|
||||||
@@ -212,6 +238,16 @@ export function CircularTimeline({
|
|||||||
>
|
>
|
||||||
<circle cx={point.x} cy={point.y} r="19" className="sound-point-hit-area" />
|
<circle cx={point.x} cy={point.y} r="19" className="sound-point-hit-area" />
|
||||||
<circle cx={point.x} cy={point.y} r="10" className="sound-point-face" />
|
<circle cx={point.x} cy={point.y} r="10" className="sound-point-face" />
|
||||||
|
<text
|
||||||
|
x={point.x}
|
||||||
|
y={point.y}
|
||||||
|
className="sound-point-letter"
|
||||||
|
textAnchor="middle"
|
||||||
|
dominantBaseline="middle"
|
||||||
|
aria-hidden="true"
|
||||||
|
>
|
||||||
|
{beat.letter}
|
||||||
|
</text>
|
||||||
</g>
|
</g>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|||||||
@@ -1,82 +1 @@
|
|||||||
import { memo } from 'react';
|
export { CategoryRingSelector as SoundRingSelector } from './CategoryRingSelector';
|
||||||
import { IonButton, IonIcon, IonPopover } from '@ionic/react';
|
|
||||||
import { chevronDown } from 'ionicons/icons';
|
|
||||||
import { INSTRUMENT_BY_ID } from '../domain/instruments';
|
|
||||||
import type { InstrumentId } from '../domain/instruments';
|
|
||||||
import { usePopoverDisclosure } from '../hooks/usePopoverDisclosure';
|
|
||||||
|
|
||||||
interface SoundRingSelectorProps {
|
|
||||||
soundIds: InstrumentId[];
|
|
||||||
focusedSoundId: InstrumentId | null;
|
|
||||||
colorBySoundId: Partial<Record<InstrumentId, string>>;
|
|
||||||
onSelectSound: (soundId: InstrumentId) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SoundRingSelector = memo(function SoundRingSelector({
|
|
||||||
soundIds,
|
|
||||||
focusedSoundId,
|
|
||||||
colorBySoundId,
|
|
||||||
onSelectSound,
|
|
||||||
}: SoundRingSelectorProps) {
|
|
||||||
const popover = usePopoverDisclosure();
|
|
||||||
const focusedSound = focusedSoundId ? INSTRUMENT_BY_ID[focusedSoundId] : undefined;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<IonButton
|
|
||||||
id="sound-ring-selector-trigger"
|
|
||||||
className="sound-ring-selector-trigger"
|
|
||||||
fill="clear"
|
|
||||||
disabled={soundIds.length === 0}
|
|
||||||
aria-label={focusedSound ? `Selected ring: ${focusedSound.label}` : 'Select a sound ring'}
|
|
||||||
aria-haspopup="dialog"
|
|
||||||
aria-expanded={popover.isOpen}
|
|
||||||
>
|
|
||||||
<span className="sound-ring-trigger-content">
|
|
||||||
{focusedSoundId && (
|
|
||||||
<span
|
|
||||||
className="ring-selector-swatch"
|
|
||||||
style={{ backgroundColor: colorBySoundId[focusedSoundId] ?? '#b8b4e0' }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<span>{focusedSound ? `${focusedSound.label} ring` : 'Sound rings'}</span>
|
|
||||||
<IonIcon icon={chevronDown} />
|
|
||||||
</span>
|
|
||||||
</IonButton>
|
|
||||||
|
|
||||||
<IonPopover
|
|
||||||
className="sound-ring-popover"
|
|
||||||
trigger="sound-ring-selector-trigger"
|
|
||||||
triggerAction="click"
|
|
||||||
side="bottom"
|
|
||||||
alignment="end"
|
|
||||||
dismissOnSelect
|
|
||||||
onDidPresent={popover.onDidPresent}
|
|
||||||
onDidDismiss={popover.onDidDismiss}
|
|
||||||
>
|
|
||||||
<div className="sound-ring-options" role="group" aria-label="Sound rings">
|
|
||||||
{soundIds.map((soundId) => {
|
|
||||||
const selected = soundId === focusedSoundId;
|
|
||||||
return (
|
|
||||||
<IonButton
|
|
||||||
key={soundId}
|
|
||||||
className="sound-ring-option"
|
|
||||||
fill={selected ? 'solid' : 'clear'}
|
|
||||||
aria-pressed={selected}
|
|
||||||
onClick={() => onSelectSound(soundId)}
|
|
||||||
>
|
|
||||||
<span className="sound-ring-option-content">
|
|
||||||
<span
|
|
||||||
className="ring-selector-swatch"
|
|
||||||
style={{ backgroundColor: colorBySoundId[soundId] ?? '#b8b4e0' }}
|
|
||||||
/>
|
|
||||||
<span>{INSTRUMENT_BY_ID[soundId].label} ring</span>
|
|
||||||
</span>
|
|
||||||
</IonButton>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</IonPopover>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
});
|
|
||||||
@@ -136,6 +136,7 @@ export type InstrumentCategoryId = InstrumentDefinition['categoryId'];
|
|||||||
export interface InstrumentCategory {
|
export interface InstrumentCategory {
|
||||||
id: InstrumentCategoryId;
|
id: InstrumentCategoryId;
|
||||||
label: string;
|
label: string;
|
||||||
|
letter: string;
|
||||||
instrumentIds: readonly InstrumentId[];
|
instrumentIds: readonly InstrumentId[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,19 +149,33 @@ export function isInstrumentId(value: unknown): value is InstrumentId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const INSTRUMENT_CATEGORIES = [
|
export const INSTRUMENT_CATEGORIES = [
|
||||||
{ id: 'drums', label: 'Drums', instrumentIds: ['kick', 'snare', 'hi-hat', 'toms', 'cymbals'] },
|
{
|
||||||
|
id: 'drums',
|
||||||
|
label: 'Drums',
|
||||||
|
letter: 'A',
|
||||||
|
instrumentIds: ['kick', 'snare', 'hi-hat', 'toms', 'cymbals'],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
id: 'percussion',
|
id: 'percussion',
|
||||||
label: 'Percussion',
|
label: 'Percussion',
|
||||||
|
letter: 'B',
|
||||||
instrumentIds: ['clap', 'shaker', 'cowbell', 'woodblock', 'bongos'],
|
instrumentIds: ['clap', 'shaker', 'cowbell', 'woodblock', 'bongos'],
|
||||||
},
|
},
|
||||||
{ id: 'bass', label: 'Bass', instrumentIds: ['bass'] },
|
{ id: 'bass', label: 'Bass', letter: 'C', instrumentIds: ['bass'] },
|
||||||
{ id: 'keys', label: 'Keys', instrumentIds: ['piano', 'organ'] },
|
{ id: 'keys', label: 'Keys', letter: 'D', instrumentIds: ['piano', 'organ'] },
|
||||||
{ id: 'strings', label: 'Strings', instrumentIds: ['strings'] },
|
{ id: 'strings', label: 'Strings', letter: 'E', instrumentIds: ['strings'] },
|
||||||
{ id: 'winds', label: 'Winds', instrumentIds: ['winds'] },
|
{ id: 'winds', label: 'Winds', letter: 'F', instrumentIds: ['winds'] },
|
||||||
{ id: 'synth', label: 'Synth', instrumentIds: ['synth'] },
|
{ id: 'synth', label: 'Synth', letter: 'G', instrumentIds: ['synth'] },
|
||||||
] as const satisfies readonly InstrumentCategory[];
|
] as const satisfies readonly InstrumentCategory[];
|
||||||
|
|
||||||
|
export const INSTRUMENT_CATEGORY_BY_ID = INSTRUMENT_CATEGORIES.reduce(
|
||||||
|
(categories, category) => {
|
||||||
|
categories[category.id] = category;
|
||||||
|
return categories;
|
||||||
|
},
|
||||||
|
{} as Record<InstrumentCategoryId, InstrumentCategory>,
|
||||||
|
);
|
||||||
|
|
||||||
export const DEFAULT_PITCH_SEMITONES = 0;
|
export const DEFAULT_PITCH_SEMITONES = 0;
|
||||||
export const MIN_PITCH_SEMITONES = -24;
|
export const MIN_PITCH_SEMITONES = -24;
|
||||||
export const MAX_PITCH_SEMITONES = 24;
|
export const MAX_PITCH_SEMITONES = 24;
|
||||||
|
|||||||
+36
-1
@@ -1,4 +1,5 @@
|
|||||||
import type { InstrumentId } from './instruments';
|
import { INSTRUMENT_BY_ID } from './instruments';
|
||||||
|
import type { InstrumentCategoryId, InstrumentId } from './instruments';
|
||||||
|
|
||||||
export const STEPS_PER_BEAT = 4;
|
export const STEPS_PER_BEAT = 4;
|
||||||
export const PLAYBACK_SUBSTEPS_PER_STEP = 4;
|
export const PLAYBACK_SUBSTEPS_PER_STEP = 4;
|
||||||
@@ -25,12 +26,46 @@ export function getPlaybackTickDurationMs(tempoBpm: number): number {
|
|||||||
export interface BeatPoint {
|
export interface BeatPoint {
|
||||||
id: string;
|
id: string;
|
||||||
soundId: InstrumentId;
|
soundId: InstrumentId;
|
||||||
|
/** Short unique label within its instrument category, such as a, b, or c. */
|
||||||
|
letter: string;
|
||||||
/** Position in sixteenth-note steps; fractional values represent microtiming. */
|
/** Position in sixteenth-note steps; fractional values represent microtiming. */
|
||||||
step: number;
|
step: number;
|
||||||
/** Pitch offset from the instrument's base note in semitones. */
|
/** Pitch offset from the instrument's base note in semitones. */
|
||||||
pitchSemitones?: number;
|
pitchSemitones?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getAlphabeticLabel(index: number): string {
|
||||||
|
let value = Math.floor(index) + 1;
|
||||||
|
if (!Number.isSafeInteger(value) || value < 1) return '';
|
||||||
|
|
||||||
|
let label = '';
|
||||||
|
while (value > 0) {
|
||||||
|
value -= 1;
|
||||||
|
label = String.fromCharCode(65 + (value % 26)) + label;
|
||||||
|
value = Math.floor(value / 26);
|
||||||
|
}
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getNextBeatLetter(
|
||||||
|
beats: readonly BeatPoint[],
|
||||||
|
categoryId: InstrumentCategoryId,
|
||||||
|
): string {
|
||||||
|
const usedLetters = new Set(
|
||||||
|
beats
|
||||||
|
.filter((beat) => INSTRUMENT_BY_ID[beat.soundId].categoryId === categoryId)
|
||||||
|
.map((beat) => beat.letter),
|
||||||
|
);
|
||||||
|
|
||||||
|
let index = 0;
|
||||||
|
let letter = getAlphabeticLabel(index).toLowerCase();
|
||||||
|
while (usedLetters.has(letter)) {
|
||||||
|
index += 1;
|
||||||
|
letter = getAlphabeticLabel(index).toLowerCase();
|
||||||
|
}
|
||||||
|
return letter;
|
||||||
|
}
|
||||||
|
|
||||||
export function getNextAvailableStep(
|
export function getNextAvailableStep(
|
||||||
beats: readonly BeatPoint[],
|
beats: readonly BeatPoint[],
|
||||||
totalSteps = TOTAL_STEPS,
|
totalSteps = TOTAL_STEPS,
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import {
|
|||||||
TEMPO_BPM,
|
TEMPO_BPM,
|
||||||
} from './sequencer';
|
} from './sequencer';
|
||||||
import type { BeatsPerBar, BeatPoint } from './sequencer';
|
import type { BeatsPerBar, BeatPoint } from './sequencer';
|
||||||
import { clampPitchSemitones } from './instruments';
|
import { clampPitchSemitones, INSTRUMENT_BY_ID } from './instruments';
|
||||||
import type { InstrumentId } from './instruments';
|
import type { InstrumentCategoryId } from './instruments';
|
||||||
|
|
||||||
export interface SequencerState {
|
export interface SequencerState {
|
||||||
beats: BeatPoint[];
|
beats: BeatPoint[];
|
||||||
selectedBeatId: string | null;
|
selectedBeatId: string | null;
|
||||||
focusedSoundId: InstrumentId | null;
|
focusedCategoryId: InstrumentCategoryId | null;
|
||||||
tempoBpm: number;
|
tempoBpm: number;
|
||||||
beatsPerBar: BeatsPerBar;
|
beatsPerBar: BeatsPerBar;
|
||||||
}
|
}
|
||||||
@@ -21,9 +21,9 @@ export type SequencerAction =
|
|||||||
| { type: 'beat-moved'; beatId: string; step: number }
|
| { type: 'beat-moved'; beatId: string; step: number }
|
||||||
| { type: 'beat-pitch-changed'; beatId: string; pitchSemitones: number }
|
| { type: 'beat-pitch-changed'; beatId: string; pitchSemitones: number }
|
||||||
| { type: 'beat-selected'; beatId: string }
|
| { type: 'beat-selected'; beatId: string }
|
||||||
| { type: 'sound-selected'; soundId: InstrumentId }
|
| { type: 'category-selected'; categoryId: InstrumentCategoryId }
|
||||||
| { type: 'selected-beat-removed' }
|
| { type: 'selected-beat-removed' }
|
||||||
| { type: 'focused-sound-removed' }
|
| { type: 'focused-category-removed' }
|
||||||
| { type: 'tempo-changed'; tempoBpm: number }
|
| { type: 'tempo-changed'; tempoBpm: number }
|
||||||
| { type: 'time-signature-changed'; beatsPerBar: BeatsPerBar }
|
| { type: 'time-signature-changed'; beatsPerBar: BeatsPerBar }
|
||||||
| { type: 'template-loaded'; beats: BeatPoint[]; tempoBpm: number; beatsPerBar: BeatsPerBar };
|
| { type: 'template-loaded'; beats: BeatPoint[]; tempoBpm: number; beatsPerBar: BeatsPerBar };
|
||||||
@@ -32,7 +32,7 @@ export function createInitialSequencerState(): SequencerState {
|
|||||||
return {
|
return {
|
||||||
beats: [],
|
beats: [],
|
||||||
selectedBeatId: null,
|
selectedBeatId: null,
|
||||||
focusedSoundId: null,
|
focusedCategoryId: null,
|
||||||
tempoBpm: TEMPO_BPM,
|
tempoBpm: TEMPO_BPM,
|
||||||
beatsPerBar: DEFAULT_BEATS_PER_BAR,
|
beatsPerBar: DEFAULT_BEATS_PER_BAR,
|
||||||
};
|
};
|
||||||
@@ -49,7 +49,7 @@ export function sequencerReducer(state: SequencerState, action: SequencerAction)
|
|||||||
...state,
|
...state,
|
||||||
beats: [...state.beats, action.beat],
|
beats: [...state.beats, action.beat],
|
||||||
selectedBeatId: action.beat.id,
|
selectedBeatId: action.beat.id,
|
||||||
focusedSoundId: action.beat.soundId,
|
focusedCategoryId: INSTRUMENT_BY_ID[action.beat.soundId].categoryId,
|
||||||
};
|
};
|
||||||
case 'beat-moved':
|
case 'beat-moved':
|
||||||
return {
|
return {
|
||||||
@@ -70,34 +70,43 @@ export function sequencerReducer(state: SequencerState, action: SequencerAction)
|
|||||||
case 'beat-selected': {
|
case 'beat-selected': {
|
||||||
const beat = state.beats.find((candidate) => candidate.id === action.beatId);
|
const beat = state.beats.find((candidate) => candidate.id === action.beatId);
|
||||||
if (!beat) return state;
|
if (!beat) return state;
|
||||||
return { ...state, selectedBeatId: beat.id, focusedSoundId: beat.soundId };
|
return {
|
||||||
|
...state,
|
||||||
|
selectedBeatId: beat.id,
|
||||||
|
focusedCategoryId: INSTRUMENT_BY_ID[beat.soundId].categoryId,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
case 'sound-selected':
|
case 'category-selected':
|
||||||
return { ...state, focusedSoundId: action.soundId, selectedBeatId: null };
|
return { ...state, focusedCategoryId: action.categoryId, selectedBeatId: null };
|
||||||
case 'selected-beat-removed': {
|
case 'selected-beat-removed': {
|
||||||
if (!state.selectedBeatId) return state;
|
if (!state.selectedBeatId) return state;
|
||||||
const removedBeat = state.beats.find((beat) => beat.id === state.selectedBeatId);
|
const removedBeat = state.beats.find((beat) => beat.id === state.selectedBeatId);
|
||||||
if (!removedBeat) return { ...state, selectedBeatId: null };
|
if (!removedBeat) return { ...state, selectedBeatId: null };
|
||||||
|
|
||||||
const beats = state.beats.filter((beat) => beat.id !== removedBeat.id);
|
const beats = state.beats.filter((beat) => beat.id !== removedBeat.id);
|
||||||
const soundRemains = beats.some((beat) => beat.soundId === removedBeat.soundId);
|
const removedCategoryId = INSTRUMENT_BY_ID[removedBeat.soundId].categoryId;
|
||||||
|
const categoryRemains = beats.some(
|
||||||
|
(beat) => INSTRUMENT_BY_ID[beat.soundId].categoryId === removedCategoryId,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
beats,
|
beats,
|
||||||
selectedBeatId: null,
|
selectedBeatId: null,
|
||||||
focusedSoundId: state.focusedSoundId === removedBeat.soundId && !soundRemains
|
focusedCategoryId: state.focusedCategoryId === removedCategoryId && !categoryRemains
|
||||||
? beats[0]?.soundId ?? null
|
? beats[0] ? INSTRUMENT_BY_ID[beats[0].soundId].categoryId : null
|
||||||
: state.focusedSoundId,
|
: state.focusedCategoryId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'focused-sound-removed': {
|
case 'focused-category-removed': {
|
||||||
if (!state.focusedSoundId) return state;
|
if (!state.focusedCategoryId) return state;
|
||||||
const beats = state.beats.filter((beat) => beat.soundId !== state.focusedSoundId);
|
const beats = state.beats.filter(
|
||||||
|
(beat) => INSTRUMENT_BY_ID[beat.soundId].categoryId !== state.focusedCategoryId,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
beats,
|
beats,
|
||||||
selectedBeatId: null,
|
selectedBeatId: null,
|
||||||
focusedSoundId: beats[0]?.soundId ?? null,
|
focusedCategoryId: beats[0] ? INSTRUMENT_BY_ID[beats[0].soundId].categoryId : null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'tempo-changed':
|
case 'tempo-changed':
|
||||||
@@ -106,14 +115,16 @@ export function sequencerReducer(state: SequencerState, action: SequencerAction)
|
|||||||
const totalSteps = getTotalSteps(action.beatsPerBar);
|
const totalSteps = getTotalSteps(action.beatsPerBar);
|
||||||
const visibleBeats = state.beats.filter((beat) => beat.step < totalSteps);
|
const visibleBeats = state.beats.filter((beat) => beat.step < totalSteps);
|
||||||
const selectedBeat = visibleBeats.find((beat) => beat.id === state.selectedBeatId);
|
const selectedBeat = visibleBeats.find((beat) => beat.id === state.selectedBeatId);
|
||||||
const focusedSoundRemains = visibleBeats.some((beat) => beat.soundId === state.focusedSoundId);
|
const focusedCategoryRemains = visibleBeats.some(
|
||||||
|
(beat) => INSTRUMENT_BY_ID[beat.soundId].categoryId === state.focusedCategoryId,
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
beatsPerBar: action.beatsPerBar,
|
beatsPerBar: action.beatsPerBar,
|
||||||
selectedBeatId: selectedBeat?.id ?? null,
|
selectedBeatId: selectedBeat?.id ?? null,
|
||||||
focusedSoundId: focusedSoundRemains
|
focusedCategoryId: focusedCategoryRemains
|
||||||
? state.focusedSoundId
|
? state.focusedCategoryId
|
||||||
: visibleBeats[0]?.soundId ?? null,
|
: visibleBeats[0] ? INSTRUMENT_BY_ID[visibleBeats[0].soundId].categoryId : null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
case 'template-loaded': {
|
case 'template-loaded': {
|
||||||
@@ -122,7 +133,7 @@ export function sequencerReducer(state: SequencerState, action: SequencerAction)
|
|||||||
...state,
|
...state,
|
||||||
beats: action.beats,
|
beats: action.beats,
|
||||||
selectedBeatId: firstBeat?.id ?? null,
|
selectedBeatId: firstBeat?.id ?? null,
|
||||||
focusedSoundId: firstBeat?.soundId ?? null,
|
focusedCategoryId: firstBeat ? INSTRUMENT_BY_ID[firstBeat.soundId].categoryId : null,
|
||||||
tempoBpm: clampTempoBpm(action.tempoBpm),
|
tempoBpm: clampTempoBpm(action.tempoBpm),
|
||||||
beatsPerBar: action.beatsPerBar,
|
beatsPerBar: action.beatsPerBar,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { BeatPoint } from './sequencer';
|
import type { BeatPoint } from './sequencer';
|
||||||
|
import { INSTRUMENT_BY_ID } from './instruments';
|
||||||
import {
|
import {
|
||||||
PLAYBACK_SUBSTEPS_PER_STEP,
|
PLAYBACK_SUBSTEPS_PER_STEP,
|
||||||
TOTAL_STEPS,
|
TOTAL_STEPS,
|
||||||
@@ -47,10 +48,12 @@ export function wrapStepPosition(step: number, totalSteps: number): number {
|
|||||||
return ((step % totalSteps) + totalSteps) % totalSteps;
|
return ((step % totalSteps) + totalSteps) % totalSteps;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getSoundOrbitRadius(soundIndex: number, soundCount: number): number {
|
export function getCategoryOrbitRadius(categoryIndex: number, categoryCount: number): number {
|
||||||
return ORBIT_RADIUS * (soundCount + 1 - soundIndex) / (soundCount + 1);
|
return ORBIT_RADIUS * (categoryCount + 1 - categoryIndex) / (categoryCount + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getSoundOrbitRadius = getCategoryOrbitRadius;
|
||||||
|
|
||||||
export function getPlaybackTick(step: number, totalSteps: number): number {
|
export function getPlaybackTick(step: number, totalSteps: number): number {
|
||||||
const totalPlaybackTicks = totalSteps * PLAYBACK_SUBSTEPS_PER_STEP;
|
const totalPlaybackTicks = totalSteps * PLAYBACK_SUBSTEPS_PER_STEP;
|
||||||
return Math.round(step * PLAYBACK_SUBSTEPS_PER_STEP) % totalPlaybackTicks;
|
return Math.round(step * PLAYBACK_SUBSTEPS_PER_STEP) % totalPlaybackTicks;
|
||||||
@@ -64,7 +67,8 @@ export function getStackedPosition(
|
|||||||
): CirclePoint {
|
): CirclePoint {
|
||||||
const siblings = beats
|
const siblings = beats
|
||||||
.filter((candidate) => (
|
.filter((candidate) => (
|
||||||
candidate.soundId === beat.soundId
|
INSTRUMENT_BY_ID[candidate.soundId].categoryId
|
||||||
|
=== INSTRUMENT_BY_ID[beat.soundId].categoryId
|
||||||
&& getPlaybackTick(candidate.step, totalSteps) === getPlaybackTick(beat.step, totalSteps)
|
&& getPlaybackTick(candidate.step, totalSteps) === getPlaybackTick(beat.step, totalSteps)
|
||||||
))
|
))
|
||||||
.sort((first, second) => first.id.localeCompare(second.id));
|
.sort((first, second) => first.id.localeCompare(second.id));
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
import { useCallback, useMemo, useReducer, useRef } from 'react';
|
import { useCallback, useMemo, useReducer, useRef } from 'react';
|
||||||
import type { BeatTemplate } from '../domain/beatTemplates';
|
import type { BeatTemplate } from '../domain/beatTemplates';
|
||||||
import {
|
import {
|
||||||
|
getAlphabeticLabel,
|
||||||
getNextAvailableStep,
|
getNextAvailableStep,
|
||||||
|
getNextBeatLetter,
|
||||||
getTotalSteps,
|
getTotalSteps,
|
||||||
} from '../domain/sequencer';
|
} from '../domain/sequencer';
|
||||||
import type { BeatsPerBar } from '../domain/sequencer';
|
import type { BeatsPerBar } from '../domain/sequencer';
|
||||||
import type { BeatPoint } from '../domain/sequencer';
|
import type { BeatPoint } from '../domain/sequencer';
|
||||||
import { DEFAULT_PITCH_SEMITONES } from '../domain/instruments';
|
import { DEFAULT_PITCH_SEMITONES, INSTRUMENT_BY_ID } from '../domain/instruments';
|
||||||
import type { InstrumentId } from '../domain/instruments';
|
import type { InstrumentCategoryId, InstrumentId } from '../domain/instruments';
|
||||||
import { createInitialSequencerState, sequencerReducer } from '../domain/sequencerReducer';
|
import { createInitialSequencerState, sequencerReducer } from '../domain/sequencerReducer';
|
||||||
import { useBeatPlayback } from './useBeatPlayback';
|
import { useBeatPlayback } from './useBeatPlayback';
|
||||||
|
|
||||||
@@ -20,15 +22,15 @@ export interface BeatSequencer {
|
|||||||
tempoBpm: number;
|
tempoBpm: number;
|
||||||
beatsPerBar: BeatsPerBar;
|
beatsPerBar: BeatsPerBar;
|
||||||
totalSteps: number;
|
totalSteps: number;
|
||||||
focusedSoundId: InstrumentId | null;
|
focusedCategoryId: InstrumentCategoryId | null;
|
||||||
selectedBeat: BeatPoint | undefined;
|
selectedBeat: BeatPoint | undefined;
|
||||||
addBeat: (soundId: InstrumentId) => void;
|
addBeat: (soundId: InstrumentId) => void;
|
||||||
moveBeat: (beatId: string, step: number) => void;
|
moveBeat: (beatId: string, step: number) => void;
|
||||||
changeBeatPitch: (beatId: string, pitchSemitones: number) => void;
|
changeBeatPitch: (beatId: string, pitchSemitones: number) => void;
|
||||||
selectBeat: (beatId: string) => void;
|
selectBeat: (beatId: string) => void;
|
||||||
selectSound: (soundId: InstrumentId) => void;
|
selectCategory: (categoryId: InstrumentCategoryId) => void;
|
||||||
removeSelectedBeat: () => void;
|
removeSelectedBeat: () => void;
|
||||||
removeFocusedSound: () => void;
|
removeFocusedCategory: () => void;
|
||||||
setTempoBpm: (tempoBpm: number) => void;
|
setTempoBpm: (tempoBpm: number) => void;
|
||||||
setBeatsPerBar: (beatsPerBar: BeatsPerBar) => void;
|
setBeatsPerBar: (beatsPerBar: BeatsPerBar) => void;
|
||||||
loadTemplate: (template: BeatTemplate) => void;
|
loadTemplate: (template: BeatTemplate) => void;
|
||||||
@@ -41,7 +43,7 @@ export function useBeatSequencer(): BeatSequencer {
|
|||||||
undefined,
|
undefined,
|
||||||
createInitialSequencerState,
|
createInitialSequencerState,
|
||||||
);
|
);
|
||||||
const { beats, beatsPerBar, focusedSoundId, selectedBeatId, tempoBpm } = state;
|
const { beats, beatsPerBar, focusedCategoryId, selectedBeatId, tempoBpm } = state;
|
||||||
const totalSteps = getTotalSteps(beatsPerBar);
|
const totalSteps = getTotalSteps(beatsPerBar);
|
||||||
|
|
||||||
const nextBeatIdRef = useRef(1);
|
const nextBeatIdRef = useRef(1);
|
||||||
@@ -61,6 +63,7 @@ export function useBeatSequencer(): BeatSequencer {
|
|||||||
const beat: BeatPoint = {
|
const beat: BeatPoint = {
|
||||||
id: `beat-${nextBeatIdRef.current}`,
|
id: `beat-${nextBeatIdRef.current}`,
|
||||||
soundId,
|
soundId,
|
||||||
|
letter: getNextBeatLetter(beats, INSTRUMENT_BY_ID[soundId].categoryId),
|
||||||
step: getNextAvailableStep(beats, totalSteps),
|
step: getNextAvailableStep(beats, totalSteps),
|
||||||
pitchSemitones: DEFAULT_PITCH_SEMITONES,
|
pitchSemitones: DEFAULT_PITCH_SEMITONES,
|
||||||
};
|
};
|
||||||
@@ -80,16 +83,16 @@ export function useBeatSequencer(): BeatSequencer {
|
|||||||
dispatch({ type: 'beat-selected', beatId });
|
dispatch({ type: 'beat-selected', beatId });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const selectSound = useCallback((soundId: InstrumentId): void => {
|
const selectCategory = useCallback((categoryId: InstrumentCategoryId): void => {
|
||||||
dispatch({ type: 'sound-selected', soundId });
|
dispatch({ type: 'category-selected', categoryId });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const removeSelectedBeat = useCallback((): void => {
|
const removeSelectedBeat = useCallback((): void => {
|
||||||
dispatch({ type: 'selected-beat-removed' });
|
dispatch({ type: 'selected-beat-removed' });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const removeFocusedSound = useCallback((): void => {
|
const removeFocusedCategory = useCallback((): void => {
|
||||||
dispatch({ type: 'focused-sound-removed' });
|
dispatch({ type: 'focused-category-removed' });
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const setTempoBpm = useCallback((tempo: number): void => {
|
const setTempoBpm = useCallback((tempo: number): void => {
|
||||||
@@ -101,10 +104,15 @@ export function useBeatSequencer(): BeatSequencer {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const loadTemplate = useCallback((template: BeatTemplate): void => {
|
const loadTemplate = useCallback((template: BeatTemplate): void => {
|
||||||
|
const nextLetterByCategory = new Map<InstrumentCategoryId, number>();
|
||||||
const templateBeats: BeatPoint[] = template.beats.map((templateBeat) => {
|
const templateBeats: BeatPoint[] = template.beats.map((templateBeat) => {
|
||||||
|
const categoryId = INSTRUMENT_BY_ID[templateBeat.soundId].categoryId;
|
||||||
|
const letterIndex = nextLetterByCategory.get(categoryId) ?? 0;
|
||||||
|
nextLetterByCategory.set(categoryId, letterIndex + 1);
|
||||||
const beat: BeatPoint = {
|
const beat: BeatPoint = {
|
||||||
id: `beat-${nextBeatIdRef.current}`,
|
id: `beat-${nextBeatIdRef.current}`,
|
||||||
...templateBeat,
|
...templateBeat,
|
||||||
|
letter: getAlphabeticLabel(letterIndex).toLowerCase(),
|
||||||
pitchSemitones: templateBeat.pitchSemitones ?? DEFAULT_PITCH_SEMITONES,
|
pitchSemitones: templateBeat.pitchSemitones ?? DEFAULT_PITCH_SEMITONES,
|
||||||
};
|
};
|
||||||
nextBeatIdRef.current += 1;
|
nextBeatIdRef.current += 1;
|
||||||
@@ -129,15 +137,15 @@ export function useBeatSequencer(): BeatSequencer {
|
|||||||
tempoBpm,
|
tempoBpm,
|
||||||
beatsPerBar,
|
beatsPerBar,
|
||||||
totalSteps,
|
totalSteps,
|
||||||
focusedSoundId,
|
focusedCategoryId,
|
||||||
selectedBeat,
|
selectedBeat,
|
||||||
addBeat,
|
addBeat,
|
||||||
moveBeat,
|
moveBeat,
|
||||||
changeBeatPitch,
|
changeBeatPitch,
|
||||||
selectBeat,
|
selectBeat,
|
||||||
selectSound,
|
selectCategory,
|
||||||
removeSelectedBeat,
|
removeSelectedBeat,
|
||||||
removeFocusedSound,
|
removeFocusedCategory,
|
||||||
setTempoBpm,
|
setTempoBpm,
|
||||||
setBeatsPerBar,
|
setBeatsPerBar,
|
||||||
loadTemplate,
|
loadTemplate,
|
||||||
|
|||||||
@@ -5,10 +5,13 @@ import type { BeatSequencer } from './useBeatSequencer';
|
|||||||
import { useBeatSequencer } from './useBeatSequencer';
|
import { useBeatSequencer } from './useBeatSequencer';
|
||||||
import type { SoundPalette } from './useSoundPalette';
|
import type { SoundPalette } from './useSoundPalette';
|
||||||
import { useSoundPalette } from './useSoundPalette';
|
import { useSoundPalette } from './useSoundPalette';
|
||||||
|
import type { CategoryLabels } from './useCategoryLabels';
|
||||||
|
import { useCategoryLabels } from './useCategoryLabels';
|
||||||
|
|
||||||
export interface BeatStudio {
|
export interface BeatStudio {
|
||||||
sequencer: BeatSequencer;
|
sequencer: BeatSequencer;
|
||||||
soundPalette: SoundPalette;
|
soundPalette: SoundPalette;
|
||||||
|
categoryLabels: CategoryLabels;
|
||||||
addSound: (soundId: InstrumentId) => void;
|
addSound: (soundId: InstrumentId) => void;
|
||||||
applyTemplate: (template: BeatTemplate) => void;
|
applyTemplate: (template: BeatTemplate) => void;
|
||||||
}
|
}
|
||||||
@@ -16,6 +19,7 @@ export interface BeatStudio {
|
|||||||
export function useBeatStudio(): BeatStudio {
|
export function useBeatStudio(): BeatStudio {
|
||||||
const sequencer = useBeatSequencer();
|
const sequencer = useBeatSequencer();
|
||||||
const soundPalette = useSoundPalette();
|
const soundPalette = useSoundPalette();
|
||||||
|
const categoryLabels = useCategoryLabels();
|
||||||
const { addBeat, loadTemplate } = sequencer;
|
const { addBeat, loadTemplate } = sequencer;
|
||||||
const { activateSounds } = soundPalette;
|
const { activateSounds } = soundPalette;
|
||||||
|
|
||||||
@@ -29,5 +33,5 @@ export function useBeatStudio(): BeatStudio {
|
|||||||
activateSounds(template.beats.map((beat) => beat.soundId));
|
activateSounds(template.beats.map((beat) => beat.soundId));
|
||||||
}, [activateSounds, loadTemplate]);
|
}, [activateSounds, loadTemplate]);
|
||||||
|
|
||||||
return { sequencer, soundPalette, addSound, applyTemplate };
|
return { sequencer, soundPalette, categoryLabels, addSound, applyTemplate };
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { useCallback, useState } from 'react';
|
||||||
|
import type { InstrumentCategoryId } from '../domain/instruments';
|
||||||
|
|
||||||
|
export type CategoryLabelOverrides = Partial<Record<InstrumentCategoryId, string>>;
|
||||||
|
|
||||||
|
export interface CategoryLabels {
|
||||||
|
labelByCategoryId: CategoryLabelOverrides;
|
||||||
|
renameCategory: (categoryId: InstrumentCategoryId, label: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useCategoryLabels(): CategoryLabels {
|
||||||
|
const [labelByCategoryId, setLabelByCategoryId] = useState<CategoryLabelOverrides>({});
|
||||||
|
|
||||||
|
const renameCategory = useCallback((categoryId: InstrumentCategoryId, label: string): void => {
|
||||||
|
const trimmedLabel = label.trim();
|
||||||
|
if (!trimmedLabel) return;
|
||||||
|
|
||||||
|
setLabelByCategoryId((currentLabels) => ({
|
||||||
|
...currentLabels,
|
||||||
|
[categoryId]: trimmedLabel,
|
||||||
|
}));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return { labelByCategoryId, renameCategory };
|
||||||
|
}
|
||||||
@@ -1,44 +1,50 @@
|
|||||||
import { useCallback, useMemo, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
import type { InstrumentId } from '../domain/instruments';
|
import { INSTRUMENT_BY_ID, INSTRUMENT_CATEGORIES } from '../domain/instruments';
|
||||||
|
import type { InstrumentCategoryId, InstrumentId } from '../domain/instruments';
|
||||||
import { generateUniqueSoundColor } from '../domain/soundColors';
|
import { generateUniqueSoundColor } from '../domain/soundColors';
|
||||||
|
|
||||||
export interface PaletteSound {
|
export interface PaletteCategory {
|
||||||
id: InstrumentId;
|
id: InstrumentCategoryId;
|
||||||
color: string;
|
color: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SoundPalette {
|
export interface SoundPalette {
|
||||||
activeSounds: PaletteSound[];
|
activeCategories: PaletteCategory[];
|
||||||
colorBySoundId: Partial<Record<InstrumentId, string>>;
|
colorByCategoryId: Partial<Record<InstrumentCategoryId, string>>;
|
||||||
activateSounds: (soundIds: readonly InstrumentId[]) => void;
|
activateSounds: (instrumentIds: readonly InstrumentId[]) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSoundPalette(): SoundPalette {
|
export function useSoundPalette(): SoundPalette {
|
||||||
const [activeSounds, setActiveSounds] = useState<PaletteSound[]>([]);
|
const [activeCategories, setActiveCategories] = useState<PaletteCategory[]>([]);
|
||||||
|
|
||||||
const activateSounds = useCallback((soundIds: readonly InstrumentId[]): void => {
|
const activateSounds = useCallback((instrumentIds: readonly InstrumentId[]): void => {
|
||||||
setActiveSounds((currentSounds) => {
|
setActiveCategories((currentCategories) => {
|
||||||
const nextSounds = [...currentSounds];
|
const nextCategories = [...currentCategories];
|
||||||
const currentCount = nextSounds.length;
|
const currentCount = nextCategories.length;
|
||||||
soundIds.forEach((soundId) => {
|
const categoryIds = instrumentIds.map(
|
||||||
if (nextSounds.some((sound) => sound.id === soundId)) return;
|
(instrumentId) => INSTRUMENT_BY_ID[instrumentId].categoryId,
|
||||||
|
);
|
||||||
|
INSTRUMENT_CATEGORIES
|
||||||
|
.filter((category) => categoryIds.includes(category.id))
|
||||||
|
.forEach((category) => {
|
||||||
|
if (nextCategories.some((active) => active.id === category.id)) return;
|
||||||
|
|
||||||
nextSounds.push({
|
nextCategories.push({
|
||||||
id: soundId,
|
id: category.id,
|
||||||
color: generateUniqueSoundColor(nextSounds.map((sound) => sound.color)),
|
color: generateUniqueSoundColor(nextCategories.map((active) => active.color)),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
return nextCategories.length === currentCount ? currentCategories : nextCategories;
|
||||||
return nextSounds.length === currentCount ? currentSounds : nextSounds;
|
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const colorBySoundId = useMemo(() => {
|
const colorByCategoryId = useMemo(() => {
|
||||||
const colors: Partial<Record<InstrumentId, string>> = {};
|
const colors: Partial<Record<InstrumentCategoryId, string>> = {};
|
||||||
activeSounds.forEach((sound) => {
|
activeCategories.forEach((category) => {
|
||||||
colors[sound.id] = sound.color;
|
colors[category.id] = category.color;
|
||||||
});
|
});
|
||||||
return colors;
|
return colors;
|
||||||
}, [activeSounds]);
|
}, [activeCategories]);
|
||||||
|
|
||||||
return { activeSounds, colorBySoundId, activateSounds };
|
return { activeCategories, colorByCategoryId, activateSounds };
|
||||||
}
|
}
|
||||||
+57
-21
@@ -11,11 +11,14 @@ import {
|
|||||||
INSTRUMENT_CATEGORIES,
|
INSTRUMENT_CATEGORIES,
|
||||||
INSTRUMENT_CATALOG,
|
INSTRUMENT_CATALOG,
|
||||||
INSTRUMENT_BY_ID,
|
INSTRUMENT_BY_ID,
|
||||||
|
INSTRUMENT_CATEGORY_BY_ID,
|
||||||
MAX_PITCH_SEMITONES,
|
MAX_PITCH_SEMITONES,
|
||||||
MIN_PITCH_SEMITONES,
|
MIN_PITCH_SEMITONES,
|
||||||
} from './domain/instruments';
|
} from './domain/instruments';
|
||||||
import { INSTRUMENT_VOICES } from './audio/soundVoices';
|
import { INSTRUMENT_VOICES } from './audio/soundVoices';
|
||||||
import {
|
import {
|
||||||
|
getAlphabeticLabel,
|
||||||
|
getNextBeatLetter,
|
||||||
getNextAvailableStep,
|
getNextAvailableStep,
|
||||||
getPlaybackTickDurationMs,
|
getPlaybackTickDurationMs,
|
||||||
getLoopPositionPercent,
|
getLoopPositionPercent,
|
||||||
@@ -30,6 +33,7 @@ import {
|
|||||||
TEMPO_BPM,
|
TEMPO_BPM,
|
||||||
} from './sequencer';
|
} from './sequencer';
|
||||||
import type { BeatPoint } from './sequencer';
|
import type { BeatPoint } from './sequencer';
|
||||||
|
import { getStackedPosition } from './domain/timeline';
|
||||||
|
|
||||||
describe('circular step positions', () => {
|
describe('circular step positions', () => {
|
||||||
it('derives playback timing from tempo and fine-grained subdivisions', () => {
|
it('derives playback timing from tempo and fine-grained subdivisions', () => {
|
||||||
@@ -72,6 +76,17 @@ describe('circular step positions', () => {
|
|||||||
expect(getStepFromPosition(point.x, point.y)).toBeCloseTo(fractionalStep, 8);
|
expect(getStepFromPosition(point.x, point.y)).toBeCloseTo(fractionalStep, 8);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('visually separates same-category instruments at the same beat tick', () => {
|
||||||
|
const beats: BeatPoint[] = [
|
||||||
|
{ id: 'kick-a', soundId: 'kick', letter: 'a', step: 4 },
|
||||||
|
{ id: 'snare-b', soundId: 'snare', letter: 'b', step: 4 },
|
||||||
|
];
|
||||||
|
const kickPosition = getStackedPosition(beats[0], beats, TOTAL_STEPS, 180);
|
||||||
|
const snarePosition = getStackedPosition(beats[1], beats, TOTAL_STEPS, 180);
|
||||||
|
|
||||||
|
expect(kickPosition).not.toEqual(snarePosition);
|
||||||
|
});
|
||||||
|
|
||||||
it('wraps fractional positions and reports loop percentages', () => {
|
it('wraps fractional positions and reports loop percentages', () => {
|
||||||
expect(wrapStepPosition(16.25, 16)).toBeCloseTo(0.25);
|
expect(wrapStepPosition(16.25, 16)).toBeCloseTo(0.25);
|
||||||
expect(wrapStepPosition(-0.25, 16)).toBeCloseTo(15.75);
|
expect(wrapStepPosition(-0.25, 16)).toBeCloseTo(15.75);
|
||||||
@@ -80,8 +95,8 @@ describe('circular step positions', () => {
|
|||||||
|
|
||||||
it('adds a sound at the next empty step', () => {
|
it('adds a sound at the next empty step', () => {
|
||||||
const beats: BeatPoint[] = [
|
const beats: BeatPoint[] = [
|
||||||
{ id: 'first', soundId: 'kick', step: 0 },
|
{ id: 'first', soundId: 'kick', letter: 'a', step: 0 },
|
||||||
{ id: 'second', soundId: 'hi-hat', step: 1 },
|
{ id: 'second', soundId: 'hi-hat', letter: 'b', step: 1 },
|
||||||
];
|
];
|
||||||
expect(getNextAvailableStep(beats)).toBe(2);
|
expect(getNextAvailableStep(beats)).toBe(2);
|
||||||
});
|
});
|
||||||
@@ -90,6 +105,7 @@ describe('circular step positions', () => {
|
|||||||
const beats: BeatPoint[] = Array.from({ length: TOTAL_STEPS }, (_, step) => ({
|
const beats: BeatPoint[] = Array.from({ length: TOTAL_STEPS }, (_, step) => ({
|
||||||
id: `beat-${step}`,
|
id: `beat-${step}`,
|
||||||
soundId: 'kick',
|
soundId: 'kick',
|
||||||
|
letter: getAlphabeticLabel(step).toLowerCase(),
|
||||||
step,
|
step,
|
||||||
}));
|
}));
|
||||||
expect(getNextAvailableStep(beats)).toBe(0);
|
expect(getNextAvailableStep(beats)).toBe(0);
|
||||||
@@ -100,6 +116,7 @@ describe('circular step positions', () => {
|
|||||||
const beats: BeatPoint[] = Array.from({ length: totalSteps }, (_, step) => ({
|
const beats: BeatPoint[] = Array.from({ length: totalSteps }, (_, step) => ({
|
||||||
id: `beat-${step}`,
|
id: `beat-${step}`,
|
||||||
soundId: 'kick',
|
soundId: 'kick',
|
||||||
|
letter: getAlphabeticLabel(step).toLowerCase(),
|
||||||
step,
|
step,
|
||||||
}));
|
}));
|
||||||
expect(getNextAvailableStep(beats, totalSteps)).toBe(0);
|
expect(getNextAvailableStep(beats, totalSteps)).toBe(0);
|
||||||
@@ -125,6 +142,8 @@ describe('instrument catalog and pitch', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(new Set(categorizedInstruments).size).toBe(INSTRUMENT_CATALOG.length);
|
expect(new Set(categorizedInstruments).size).toBe(INSTRUMENT_CATALOG.length);
|
||||||
|
expect(new Set(INSTRUMENT_CATEGORIES.map((category) => category.letter)).size)
|
||||||
|
.toBe(INSTRUMENT_CATEGORIES.length);
|
||||||
INSTRUMENT_CATALOG.forEach((instrument) => {
|
INSTRUMENT_CATALOG.forEach((instrument) => {
|
||||||
expect(categorizedInstruments).toContain(instrument.id);
|
expect(categorizedInstruments).toContain(instrument.id);
|
||||||
expect(typeof INSTRUMENT_VOICES[instrument.id]).toBe('function');
|
expect(typeof INSTRUMENT_VOICES[instrument.id]).toBe('function');
|
||||||
@@ -140,14 +159,27 @@ describe('instrument catalog and pitch', () => {
|
|||||||
expect(getPitchLabel(MAX_PITCH_SEMITONES)).toBe('C6');
|
expect(getPitchLabel(MAX_PITCH_SEMITONES)).toBe('C6');
|
||||||
expect(getPitchLabel(0, INSTRUMENT_BY_ID.kick.pitchBaseMidi)).toBe('F3');
|
expect(getPitchLabel(0, INSTRUMENT_BY_ID.kick.pitchBaseMidi)).toBe('F3');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('assigns beat letters within their category and supports labels beyond Z', () => {
|
||||||
|
const beats: BeatPoint[] = [
|
||||||
|
{ id: 'kick-1', soundId: 'kick', letter: 'a', step: 0 },
|
||||||
|
{ id: 'snare-1', soundId: 'snare', letter: 'b', step: 4 },
|
||||||
|
{ id: 'piano-1', soundId: 'piano', letter: 'a', step: 8 },
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(getNextBeatLetter(beats, 'drums')).toBe('c');
|
||||||
|
expect(getNextBeatLetter(beats, 'keys')).toBe('b');
|
||||||
|
expect(getAlphabeticLabel(26)).toBe('AA');
|
||||||
|
expect(INSTRUMENT_CATEGORY_BY_ID.drums.letter).toBe('A');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('sequencer state transitions', () => {
|
describe('sequencer state transitions', () => {
|
||||||
it('loads a template with a focused first beat and removes a focused sound ring', () => {
|
it('loads a template and removes every instrument in the focused category ring', () => {
|
||||||
const templateBeats: BeatPoint[] = [
|
const templateBeats: BeatPoint[] = [
|
||||||
{ id: 'kick-1', soundId: 'kick', step: 0 },
|
{ id: 'kick-1', soundId: 'kick', letter: 'a', step: 0 },
|
||||||
{ id: 'kick-2', soundId: 'kick', step: 4 },
|
{ id: 'snare-1', soundId: 'snare', letter: 'b', step: 4 },
|
||||||
{ id: 'hat-1', soundId: 'hi-hat', step: 8 },
|
{ id: 'piano-1', soundId: 'piano', letter: 'a', step: 8 },
|
||||||
];
|
];
|
||||||
const loaded = sequencerReducer(createInitialSequencerState(), {
|
const loaded = sequencerReducer(createInitialSequencerState(), {
|
||||||
type: 'template-loaded',
|
type: 'template-loaded',
|
||||||
@@ -157,18 +189,18 @@ describe('sequencer state transitions', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(loaded.selectedBeatId).toBe('kick-1');
|
expect(loaded.selectedBeatId).toBe('kick-1');
|
||||||
expect(loaded.focusedSoundId).toBe('kick');
|
expect(loaded.focusedCategoryId).toBe('drums');
|
||||||
|
|
||||||
const afterRingRemoval = sequencerReducer(loaded, { type: 'focused-sound-removed' });
|
const afterRingRemoval = sequencerReducer(loaded, { type: 'focused-category-removed' });
|
||||||
expect(afterRingRemoval.beats).toEqual([templateBeats[2]]);
|
expect(afterRingRemoval.beats).toEqual([templateBeats[2]]);
|
||||||
expect(afterRingRemoval.selectedBeatId).toBeNull();
|
expect(afterRingRemoval.selectedBeatId).toBeNull();
|
||||||
expect(afterRingRemoval.focusedSoundId).toBe('hi-hat');
|
expect(afterRingRemoval.focusedCategoryId).toBe('keys');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('clears out-of-range selections when the time signature gets shorter', () => {
|
it('clears out-of-range selections when the time signature gets shorter', () => {
|
||||||
const beats: BeatPoint[] = [
|
const beats: BeatPoint[] = [
|
||||||
{ id: 'hat-1', soundId: 'hi-hat', step: 0 },
|
{ id: 'hat-1', soundId: 'hi-hat', letter: 'a', step: 0 },
|
||||||
{ id: 'kick-1', soundId: 'kick', step: 12 },
|
{ id: 'kick-1', soundId: 'kick', letter: 'b', step: 12 },
|
||||||
];
|
];
|
||||||
const loaded = sequencerReducer(createInitialSequencerState(), {
|
const loaded = sequencerReducer(createInitialSequencerState(), {
|
||||||
type: 'template-loaded',
|
type: 'template-loaded',
|
||||||
@@ -184,13 +216,14 @@ describe('sequencer state transitions', () => {
|
|||||||
|
|
||||||
expect(shortened.beats).toEqual(beats);
|
expect(shortened.beats).toEqual(beats);
|
||||||
expect(shortened.selectedBeatId).toBeNull();
|
expect(shortened.selectedBeatId).toBeNull();
|
||||||
expect(shortened.focusedSoundId).toBe('hi-hat');
|
expect(shortened.focusedCategoryId).toBe('drums');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('removes a focused sound and keeps the remaining ring selected', () => {
|
it('removes one category ring and focuses a remaining category', () => {
|
||||||
const beats: BeatPoint[] = [
|
const beats: BeatPoint[] = [
|
||||||
{ id: 'kick-1', soundId: 'kick', step: 0 },
|
{ id: 'kick-1', soundId: 'kick', letter: 'a', step: 0 },
|
||||||
{ id: 'hat-1', soundId: 'hi-hat', step: 4 },
|
{ id: 'hat-1', soundId: 'hi-hat', letter: 'b', step: 4 },
|
||||||
|
{ id: 'bass-1', soundId: 'bass', letter: 'a', step: 8 },
|
||||||
];
|
];
|
||||||
const loaded = sequencerReducer(createInitialSequencerState(), {
|
const loaded = sequencerReducer(createInitialSequencerState(), {
|
||||||
type: 'template-loaded',
|
type: 'template-loaded',
|
||||||
@@ -198,11 +231,14 @@ describe('sequencer state transitions', () => {
|
|||||||
tempoBpm: TEMPO_BPM,
|
tempoBpm: TEMPO_BPM,
|
||||||
beatsPerBar: 4,
|
beatsPerBar: 4,
|
||||||
});
|
});
|
||||||
const hatSelected = sequencerReducer(loaded, { type: 'sound-selected', soundId: 'hi-hat' });
|
const bassSelected = sequencerReducer(loaded, {
|
||||||
const removed = sequencerReducer(hatSelected, { type: 'focused-sound-removed' });
|
type: 'category-selected',
|
||||||
|
categoryId: 'bass',
|
||||||
|
});
|
||||||
|
const removed = sequencerReducer(bassSelected, { type: 'focused-category-removed' });
|
||||||
|
|
||||||
expect(removed.beats).toEqual([beats[0]]);
|
expect(removed.beats).toEqual([beats[0], beats[1]]);
|
||||||
expect(removed.focusedSoundId).toBe('kick');
|
expect(removed.focusedCategoryId).toBe('drums');
|
||||||
expect(removed.selectedBeatId).toBeNull();
|
expect(removed.selectedBeatId).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -217,8 +253,8 @@ describe('sequencer state transitions', () => {
|
|||||||
|
|
||||||
it('changes pitch on one selected beat and clamps it to the supported range', () => {
|
it('changes pitch on one selected beat and clamps it to the supported range', () => {
|
||||||
const beats: BeatPoint[] = [
|
const beats: BeatPoint[] = [
|
||||||
{ id: 'bass-1', soundId: 'bass', step: 0, pitchSemitones: 0 },
|
{ id: 'bass-1', soundId: 'bass', letter: 'a', step: 0, pitchSemitones: 0 },
|
||||||
{ id: 'piano-1', soundId: 'piano', step: 4, pitchSemitones: 0 },
|
{ id: 'piano-1', soundId: 'piano', letter: 'a', step: 4, pitchSemitones: 0 },
|
||||||
];
|
];
|
||||||
const loaded = sequencerReducer(createInitialSequencerState(), {
|
const loaded = sequencerReducer(createInitialSequencerState(), {
|
||||||
type: 'template-loaded',
|
type: 'template-loaded',
|
||||||
|
|||||||
+90
-28
@@ -108,14 +108,6 @@ ion-content.app-content {
|
|||||||
letter-spacing: 1px;
|
letter-spacing: 1px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header-tag {
|
|
||||||
color: var(--soft);
|
|
||||||
font-family: 'DM Sans', sans-serif;
|
|
||||||
font-size: 12px;
|
|
||||||
font-weight: 500;
|
|
||||||
letter-spacing: 0.1px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.app-header-actions {
|
.app-header-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
@@ -328,8 +320,9 @@ ion-content.app-content {
|
|||||||
.studio-heading h1 {
|
.studio-heading h1 {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
color: var(--ink);
|
color: var(--ink);
|
||||||
font: 500 clamp(34px, 7vw, 44px)/1.1 var(--display);
|
font: 500 clamp(24px, 6vw, 40px)/1.1 var(--display);
|
||||||
letter-spacing: -1.8px;
|
letter-spacing: -1.1px;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.template-prompt {
|
.template-prompt {
|
||||||
@@ -592,6 +585,17 @@ ion-content.app-content {
|
|||||||
transition: r 720ms cubic-bezier(0.22, 1.15, 0.36, 1);
|
transition: r 720ms cubic-bezier(0.22, 1.15, 0.36, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.timeline-category-letter circle {
|
||||||
|
fill: var(--base);
|
||||||
|
stroke: currentColor;
|
||||||
|
stroke-width: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timeline-category-letter text {
|
||||||
|
fill: currentColor;
|
||||||
|
font: 700 9px var(--mono);
|
||||||
|
}
|
||||||
|
|
||||||
.timeline-tick line {
|
.timeline-tick line {
|
||||||
stroke: rgba(var(--primary-rgb), 0.34);
|
stroke: rgba(var(--primary-rgb), 0.34);
|
||||||
stroke-width: 1;
|
stroke-width: 1;
|
||||||
@@ -648,6 +652,13 @@ ion-content.app-content {
|
|||||||
filter 120ms ease;
|
filter 120ms ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sound-point-letter {
|
||||||
|
fill: var(--base);
|
||||||
|
font: 700 9px var(--mono);
|
||||||
|
pointer-events: none;
|
||||||
|
text-transform: lowercase;
|
||||||
|
}
|
||||||
|
|
||||||
.sound-point:hover .sound-point-face,
|
.sound-point:hover .sound-point-face,
|
||||||
.sound-point.is-selected .sound-point-face,
|
.sound-point.is-selected .sound-point-face,
|
||||||
.sound-point:focus-visible .sound-point-face {
|
.sound-point:focus-visible .sound-point-face {
|
||||||
@@ -742,17 +753,79 @@ ion-content.app-content {
|
|||||||
|
|
||||||
.sound-legend {
|
.sound-legend {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 22px;
|
align-items: flex-start;
|
||||||
|
gap: 8px 12px;
|
||||||
padding-top: 17px;
|
padding-top: 17px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.legend-sound {
|
.legend-category-entry {
|
||||||
display: inline-flex;
|
display: flex;
|
||||||
|
max-width: 220px;
|
||||||
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 7px;
|
}
|
||||||
|
|
||||||
|
.legend-category {
|
||||||
|
display: inline-flex;
|
||||||
|
height: 30px;
|
||||||
|
align-items: center;
|
||||||
|
margin: 0;
|
||||||
|
--color: var(--muted);
|
||||||
|
--background: transparent;
|
||||||
|
--background-hover: rgba(var(--primary-rgb), 0.08);
|
||||||
|
--background-activated: rgba(var(--primary-rgb), 0.12);
|
||||||
|
--border-radius: 7px;
|
||||||
|
font-size: 10px;
|
||||||
|
text-transform: none;
|
||||||
|
touch-action: manipulation;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend-category::part(native) {
|
||||||
|
gap: 6px;
|
||||||
|
min-height: 30px;
|
||||||
|
padding: 0 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend-category-letter,
|
||||||
|
.category-letter-badge {
|
||||||
|
display: inline-flex;
|
||||||
|
width: 17px;
|
||||||
|
height: 17px;
|
||||||
|
flex: 0 0 17px;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
border: 1px solid currentColor;
|
||||||
|
border-radius: 50%;
|
||||||
|
color: var(--ink);
|
||||||
|
font: 600 9px var(--mono);
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend-category .legend-category-letter {
|
||||||
color: var(--muted);
|
color: var(--muted);
|
||||||
font-size: 11px;
|
}
|
||||||
|
|
||||||
|
.legend-beat-list {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 2px 7px;
|
||||||
|
padding: 0 4px;
|
||||||
|
color: var(--soft);
|
||||||
|
font-size: 9px;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend-beat-list span {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.legend-beat-list strong {
|
||||||
|
color: var(--ink);
|
||||||
|
font-family: var(--mono);
|
||||||
|
text-transform: lowercase;
|
||||||
}
|
}
|
||||||
|
|
||||||
.legend-empty {
|
.legend-empty {
|
||||||
@@ -1150,12 +1223,6 @@ ion-popover.instrument-picker-popover {
|
|||||||
flex-basis: 36px;
|
flex-basis: 36px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header-tag {
|
|
||||||
font-size: 9px;
|
|
||||||
letter-spacing: 0;
|
|
||||||
max-width: 115px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.about-view {
|
.about-view {
|
||||||
padding: 31px 0 24px;
|
padding: 31px 0 24px;
|
||||||
}
|
}
|
||||||
@@ -1195,7 +1262,8 @@ ion-popover.instrument-picker-popover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.studio-heading h1 {
|
.studio-heading h1 {
|
||||||
font-size: 36px;
|
font-size: clamp(20px, 5.5vw, 32px);
|
||||||
|
letter-spacing: -0.75px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.template-prompt {
|
.template-prompt {
|
||||||
@@ -1259,12 +1327,6 @@ ion-popover.instrument-picker-popover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 360px) {
|
@media (max-width: 360px) {
|
||||||
.header-tag {
|
|
||||||
max-width: 90px;
|
|
||||||
font-size: 8px;
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
|
|
||||||
.transport-inner {
|
.transport-inner {
|
||||||
gap: 5px;
|
gap: 5px;
|
||||||
padding-right: 10px;
|
padding-right: 10px;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export function StudioView({ studio }: StudioViewProps) {
|
|||||||
return (
|
return (
|
||||||
<main id="studio" className="studio">
|
<main id="studio" className="studio">
|
||||||
<div className="studio-heading">
|
<div className="studio-heading">
|
||||||
<h1>Build a beat.</h1>
|
<h1>Sharpen your sense of rhythm</h1>
|
||||||
<p className="template-prompt">Choose a dance template</p>
|
<p className="template-prompt">Choose a dance template</p>
|
||||||
<BeatTemplateSelector onSelectTemplate={studio.applyTemplate} />
|
<BeatTemplateSelector onSelectTemplate={studio.applyTemplate} />
|
||||||
<p
|
<p
|
||||||
@@ -21,7 +21,11 @@ export function StudioView({ studio }: StudioViewProps) {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<BeatLoopPanel sequencer={studio.sequencer} soundPalette={studio.soundPalette} />
|
<BeatLoopPanel
|
||||||
|
sequencer={studio.sequencer}
|
||||||
|
soundPalette={studio.soundPalette}
|
||||||
|
categoryLabels={studio.categoryLabels}
|
||||||
|
/>
|
||||||
|
|
||||||
{studio.sequencer.audioError && (
|
{studio.sequencer.audioError && (
|
||||||
<p className="audio-error" role="alert">{studio.sequencer.audioError}</p>
|
<p className="audio-error" role="alert">{studio.sequencer.audioError}</p>
|
||||||
|
|||||||
Reference in new issue
Block a user