@molecule/app-feature-piano-roll-angular 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +598 -2
- package/dist/geometry.d.ts +91 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +150 -0
- package/dist/geometry.js.map +1 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/piano-roll.component.d.ts +345 -0
- package/dist/piano-roll.component.d.ts.map +1 -0
- package/dist/piano-roll.component.js +789 -0
- package/dist/piano-roll.component.js.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +73 -4
package/README.md
CHANGED
|
@@ -1,3 +1,599 @@
|
|
|
1
|
-
|
|
1
|
+
<!--
|
|
2
|
+
AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
3
|
+
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
|
+
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
|
+
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
+
Generated: 2026-11-21T12:46:32.110Z
|
|
7
|
+
-->
|
|
2
8
|
|
|
3
|
-
|
|
9
|
+
# @molecule/app-feature-piano-roll-angular
|
|
10
|
+
|
|
11
|
+
Angular piano roll — MIDI note-grid editor for music-daw and other
|
|
12
|
+
DAW-style surfaces. Renders a vertical piano keyboard on the left, a
|
|
13
|
+
horizontal time grid on the right, and draggable / resizable note rectangles
|
|
14
|
+
on top.
|
|
15
|
+
|
|
16
|
+
Angular counterpart of `@molecule/app-feature-piano-roll-react`: the same
|
|
17
|
+
props (React names), the same DOM for the same input, and the same callback
|
|
18
|
+
calls, so an app switches framework by changing only the package name it
|
|
19
|
+
imports.
|
|
20
|
+
|
|
21
|
+
> **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
|
|
22
|
+
> It is written to be read by coding agents as much as by people, and is generated from this
|
|
23
|
+
> package's source — edit `src/index.ts` JSDoc, not this file.
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { Component } from '@angular/core'
|
|
29
|
+
import { PianoRoll, type MidiNote } from '@molecule/app-feature-piano-roll-angular'
|
|
30
|
+
|
|
31
|
+
@Component({
|
|
32
|
+
selector: 'app-roll',
|
|
33
|
+
standalone: true,
|
|
34
|
+
imports: [PianoRoll],
|
|
35
|
+
template: `
|
|
36
|
+
<div
|
|
37
|
+
mol-piano-roll
|
|
38
|
+
[notes]="notes"
|
|
39
|
+
snap="1/16"
|
|
40
|
+
[onNoteAdd]="addNote"
|
|
41
|
+
[onNoteMove]="moveNote"
|
|
42
|
+
[onNoteResize]="resizeNote"
|
|
43
|
+
[onNoteDelete]="deleteNote"
|
|
44
|
+
></div>
|
|
45
|
+
`,
|
|
46
|
+
})
|
|
47
|
+
export class Roll {
|
|
48
|
+
notes: MidiNote[] = []
|
|
49
|
+
addNote = (note: MidiNote): void => {
|
|
50
|
+
this.notes = [...this.notes, note]
|
|
51
|
+
}
|
|
52
|
+
moveNote = (noteId: string, startBeat: number, pitch: number): void => {
|
|
53
|
+
this.notes = this.notes.map((n) => (n.id === noteId ? { ...n, startBeat, pitch } : n))
|
|
54
|
+
}
|
|
55
|
+
resizeNote = (noteId: string, durationBeats: number): void => {
|
|
56
|
+
this.notes = this.notes.map((n) => (n.id === noteId ? { ...n, durationBeats } : n))
|
|
57
|
+
}
|
|
58
|
+
deleteNote = (noteId: string): void => {
|
|
59
|
+
this.notes = this.notes.filter((n) => n.id !== noteId)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Type
|
|
65
|
+
|
|
66
|
+
`feature`
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
npm install @molecule/app-feature-piano-roll-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## API
|
|
75
|
+
|
|
76
|
+
### Interfaces
|
|
77
|
+
|
|
78
|
+
#### `MidiNote`
|
|
79
|
+
|
|
80
|
+
A single MIDI note rendered on the piano roll. `pitch` is a standard MIDI
|
|
81
|
+
pitch number in the closed interval `[0, 127]` where `60` represents middle C
|
|
82
|
+
(`C4`). `startBeat` is the note's start position on the time grid, and
|
|
83
|
+
`durationBeats` is its length in beats. `id` is a stable identifier used as
|
|
84
|
+
the row key and as the argument passed back to all event handlers.
|
|
85
|
+
`velocity` is an optional MIDI velocity in the closed interval `[0, 127]`
|
|
86
|
+
(defaults to a neutral mid-range).
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
interface MidiNote {
|
|
90
|
+
/** Stable identifier for the note (used as the row key + handler arg). */
|
|
91
|
+
id: string
|
|
92
|
+
/** MIDI pitch number, `0..127`. `60` is middle C. */
|
|
93
|
+
pitch: number
|
|
94
|
+
/** Start beat on the timeline (>= 0). */
|
|
95
|
+
startBeat: number
|
|
96
|
+
/** Duration in beats (always positive — minimum is enforced). */
|
|
97
|
+
durationBeats: number
|
|
98
|
+
/** Optional MIDI velocity, `0..127`. */
|
|
99
|
+
velocity?: number
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### `PianoRollProps`
|
|
104
|
+
|
|
105
|
+
Props accepted by the {@link PianoRoll} component.
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
interface PianoRollProps {
|
|
109
|
+
/** MIDI notes rendered on the grid. Order is preserved as-is. */
|
|
110
|
+
notes: MidiNote[]
|
|
111
|
+
/** Horizontal scale: pixels rendered per musical beat. Defaults to `80`. */
|
|
112
|
+
pixelsPerBeat?: number
|
|
113
|
+
/** Vertical row height per pitch in pixels. Defaults to `20`. */
|
|
114
|
+
noteHeight?: number
|
|
115
|
+
/** Lowest visible pitch (top-most row excluded — see `highestPitch`). Defaults to `21` (A0). */
|
|
116
|
+
lowestPitch?: number
|
|
117
|
+
/** Highest visible pitch (top-most row inclusive). Defaults to `108` (C8). */
|
|
118
|
+
highestPitch?: number
|
|
119
|
+
/** Snap resolution applied to clicks, drags, and resizes. Defaults to `'1/16'`. */
|
|
120
|
+
snap?: PianoRollSnap
|
|
121
|
+
/**
|
|
122
|
+
* Total beats rendered in the time grid. When omitted, the grid extends to
|
|
123
|
+
* cover all notes plus a small trailing pad (minimum 16 beats so empty rolls
|
|
124
|
+
* are still usable).
|
|
125
|
+
*/
|
|
126
|
+
beatsCount?: number
|
|
127
|
+
/**
|
|
128
|
+
* Called with a freshly-created note when the user paints an empty cell — by
|
|
129
|
+
* clicking it, or via the keyboard cell cursor (arrow keys to move, Enter /
|
|
130
|
+
* Space to paint).
|
|
131
|
+
*/
|
|
132
|
+
onNoteAdd?: (note: MidiNote) => void
|
|
133
|
+
/** Called with the updated note when a note is dragged horizontally / vertically. */
|
|
134
|
+
onNoteMove?: (noteId: string, startBeat: number, pitch: number) => void
|
|
135
|
+
/** Called with the updated duration when a note's right-edge handle is dragged. */
|
|
136
|
+
onNoteResize?: (noteId: string, durationBeats: number) => void
|
|
137
|
+
/** Called when the user right-clicks a note. */
|
|
138
|
+
onNoteDelete?: (noteId: string) => void
|
|
139
|
+
/** Extra classes merged onto the root element. */
|
|
140
|
+
className?: string
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Types
|
|
145
|
+
|
|
146
|
+
#### `PianoRollSnap`
|
|
147
|
+
|
|
148
|
+
Snap resolution for note placement / movement / resize. Each value is a
|
|
149
|
+
fraction of a beat: `'1/16'` is sixteenth-notes (a quarter of a beat), `'1/4'`
|
|
150
|
+
is quarter-notes (one beat), `'1'` snaps to whole beats with no
|
|
151
|
+
sub-divisions, etc.
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
type PianoRollSnap = '1/16' | '1/8' | '1/4' | '1/2' | '1'
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Classes
|
|
158
|
+
|
|
159
|
+
#### `PianoRoll`
|
|
160
|
+
|
|
161
|
+
PianoRoll component.
|
|
162
|
+
|
|
163
|
+
The host IS React's root `<div>` (`div[mol-piano-roll]`), matching React's
|
|
164
|
+
root exactly. Renders a vertical piano keyboard on the left, a horizontal
|
|
165
|
+
time grid on the right, and draggable / resizable note rectangles on top.
|
|
166
|
+
Click an empty cell to paint a new note, drag a note body to move it
|
|
167
|
+
(snapped), drag the right-edge handle to resize, right-click a note to
|
|
168
|
+
delete it.
|
|
169
|
+
|
|
170
|
+
Keyboard users get the same paint action: focus the grid (Tab), move the
|
|
171
|
+
cell cursor with the arrow keys, and press Enter or Space to paint a new note
|
|
172
|
+
at the cursor cell.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
@Component({
|
|
176
|
+
selector: 'div[mol-piano-roll]',
|
|
177
|
+
standalone: true,
|
|
178
|
+
inputs: [
|
|
179
|
+
'notes',
|
|
180
|
+
'pixelsPerBeat',
|
|
181
|
+
'noteHeight',
|
|
182
|
+
'lowestPitch',
|
|
183
|
+
'highestPitch',
|
|
184
|
+
'snap',
|
|
185
|
+
'beatsCount',
|
|
186
|
+
'onNoteAdd',
|
|
187
|
+
'onNoteMove',
|
|
188
|
+
'onNoteResize',
|
|
189
|
+
'onNoteDelete',
|
|
190
|
+
'className',
|
|
191
|
+
],
|
|
192
|
+
host: {
|
|
193
|
+
role: 'region',
|
|
194
|
+
'data-mol-id': 'piano-roll',
|
|
195
|
+
'[attr.aria-label]': 'rollLabel()',
|
|
196
|
+
'[class]': 'classes()',
|
|
197
|
+
'[style]': 'rootStyle',
|
|
198
|
+
},
|
|
199
|
+
template: `<div role="list" [attr.aria-label]="keysLabel()" data-mol-id="piano-roll-keys" [style]="keysColumnStyle()">@for (pitch of rows(); track pitch) {<div role="listitem" data-mol-id="piano-roll-key" [attr.data-pitch]="pitch" [attr.data-key-color]="isBlackKey(pitch) ? 'black' : 'white'" [style]="keyStyle(isBlackKey(pitch))">@if (isC(pitch)) {<span data-mol-id="piano-roll-key-label" [class]="keyLabelClasses()">{{ pitchLabel(pitch) }}</span>}</div>}</div><div #grid role="application" [attr.aria-label]="gridLabel()" [attr.aria-describedby]="gridHelpId" data-mol-id="piano-roll-grid" [attr.data-snap]="snapValue()" [style]="gridSurfaceStyle()" tabindex="0" (click)="handleGridClick($event)" (keydown)="handleGridKeyDown($event)" (focusin)="setGridFocused(true)" (focusout)="setGridFocused(false)">@for (pitch of rows(); track pitch) {<div data-mol-id="piano-roll-row" [attr.data-pitch]="pitch" [attr.data-key-color]="isBlackKey(pitch) ? 'black' : 'white'" [style]="rowStyle(pitch)"></div>}@for (beat of beatLines(); track beat) {<div data-mol-id="piano-roll-beat-line" [attr.data-beat]="beat" [attr.data-bar]="beat % 4 === 0 ? 'true' : 'false'" [style]="lineStyle(beat)"></div>}@if (showsCursor()) {<div data-mol-id="piano-roll-cell-cursor" aria-hidden="true" [style]="cursorStyle()"></div>}<div [attr.id]="gridHelpId" [class]="srOnlyClass()">{{ gridHelpLabel() }}</div>@if (showsStatus()) {<div role="status" [class]="srOnlyClass()">{{ cursorLabel() }}</div>}@for (note of notes; track note.id) {<div role="button" tabindex="0" [attr.aria-label]="noteAria(note)" data-mol-id="piano-roll-note" [attr.data-note-id]="note.id" [attr.data-pitch]="note.pitch" [attr.data-start-beat]="note.startBeat" [attr.data-duration-beats]="note.durationBeats" [class]="noteClasses()" [style]="noteStyle(note)" (pointerdown)="beginDrag($event, note, 'move')" (contextmenu)="handleNoteContextMenu($event, note)"><div role="separator" [attr.aria-label]="resizeLabel()" data-mol-id="piano-roll-note-handle" [style]="handleStyle" (pointerdown)="beginDrag($event, note, 'resize')"></div></div>}</div>`,
|
|
200
|
+
})
|
|
201
|
+
export class PianoRoll implements OnInit, OnDestroy {
|
|
202
|
+
notes: MidiNote[] = []
|
|
203
|
+
pixelsPerBeat?: number
|
|
204
|
+
noteHeight?: number
|
|
205
|
+
lowestPitch?: number
|
|
206
|
+
highestPitch?: number
|
|
207
|
+
snap?: PianoRollSnap
|
|
208
|
+
beatsCount?: number
|
|
209
|
+
onNoteAdd?: PianoRollProps['onNoteAdd']
|
|
210
|
+
onNoteMove?: PianoRollProps['onNoteMove']
|
|
211
|
+
onNoteResize?: PianoRollProps['onNoteResize']
|
|
212
|
+
onNoteDelete?: PianoRollProps['onNoteDelete']
|
|
213
|
+
className?: string
|
|
214
|
+
|
|
215
|
+
@ViewChild('grid') gridRef?: ElementRef<HTMLDivElement>
|
|
216
|
+
|
|
217
|
+
readonly gridHelpId = `piano-roll-grid-help-${nextGridHelpId++}`
|
|
218
|
+
|
|
219
|
+
private readonly i18n = useTranslation()
|
|
220
|
+
|
|
221
|
+
private drag: DragState | null = null
|
|
222
|
+
|
|
223
|
+
private readonly rawCursor = signal({ beat: 0, pitch: 108 })
|
|
224
|
+
|
|
225
|
+
private readonly gridFocused = signal(false)
|
|
226
|
+
|
|
227
|
+
readonly rootStyle: Record<string, string> = {
|
|
228
|
+
display: 'flex',
|
|
229
|
+
'align-items': 'stretch',
|
|
230
|
+
width: '100%',
|
|
231
|
+
overflow: 'auto',
|
|
232
|
+
position: 'relative',
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
readonly handleStyle: Record<string, string> = {
|
|
236
|
+
position: 'absolute',
|
|
237
|
+
top: '0px',
|
|
238
|
+
right: '0px',
|
|
239
|
+
bottom: '0px',
|
|
240
|
+
width: '6px',
|
|
241
|
+
cursor: 'ew-resize',
|
|
242
|
+
'touch-action': 'none',
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
ngOnInit(): void {
|
|
246
|
+
this.rawCursor.set({ beat: 0, pitch: this.highestPitch ?? 108 })
|
|
247
|
+
window.addEventListener('pointermove', this.onMove)
|
|
248
|
+
window.addEventListener('pointerup', this.onUp)
|
|
249
|
+
window.addEventListener('pointercancel', this.onUp)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
ngOnDestroy(): void {
|
|
253
|
+
window.removeEventListener('pointermove', this.onMove)
|
|
254
|
+
window.removeEventListener('pointerup', this.onUp)
|
|
255
|
+
window.removeEventListener('pointercancel', this.onUp)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
cm(): UIClassMap {
|
|
259
|
+
return getClassMap()
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
classes(): string {
|
|
263
|
+
return this.cm().cn(this.className)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
keyLabelClasses(): string {
|
|
267
|
+
return this.cm().cn(this.cm().textSize('xs'))
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
noteClasses(): string {
|
|
271
|
+
return this.cm().cn(this.cm().cursorPointer)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
srOnlyClass(): string {
|
|
275
|
+
return this.cm().cn(this.cm().srOnly)
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
geometry(): Geometry {
|
|
279
|
+
const pixelsPerBeat = this.pixelsPerBeat ?? 80
|
|
280
|
+
const noteHeight = this.noteHeight ?? 20
|
|
281
|
+
const lowestPitch = this.lowestPitch ?? 21
|
|
282
|
+
const highestPitch = this.highestPitch ?? 108
|
|
283
|
+
const snap = this.snap ?? '1/16'
|
|
284
|
+
const safeHighest = Math.max(highestPitch, lowestPitch)
|
|
285
|
+
const safeLowest = Math.min(highestPitch, lowestPitch)
|
|
286
|
+
const rowCount = safeHighest - safeLowest + 1
|
|
287
|
+
const gridHeight = rowCount * noteHeight
|
|
288
|
+
const computedBeats =
|
|
289
|
+
this.beatsCount ??
|
|
290
|
+
Math.max(
|
|
291
|
+
16,
|
|
292
|
+
Math.ceil(
|
|
293
|
+
this.notes.reduce(
|
|
294
|
+
(max, n) => Math.max(max, (n.startBeat ?? 0) + (n.durationBeats ?? 0)),
|
|
295
|
+
0,
|
|
296
|
+
) + 4,
|
|
297
|
+
),
|
|
298
|
+
)
|
|
299
|
+
return {
|
|
300
|
+
pixelsPerBeat,
|
|
301
|
+
noteHeight,
|
|
302
|
+
snap,
|
|
303
|
+
safeHighest,
|
|
304
|
+
safeLowest,
|
|
305
|
+
rowCount,
|
|
306
|
+
gridHeight,
|
|
307
|
+
computedBeats,
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
cursor(): { beat: number; pitch: number } {
|
|
312
|
+
const grid = this.geometry()
|
|
313
|
+
const raw = this.rawCursor()
|
|
314
|
+
return {
|
|
315
|
+
beat: Math.max(0, Math.min(raw.beat, grid.computedBeats)),
|
|
316
|
+
pitch: Math.max(grid.safeLowest, Math.min(grid.safeHighest, raw.pitch)),
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
snapValue(): PianoRollSnap {
|
|
321
|
+
return this.snap ?? '1/16'
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
rows(): number[] {
|
|
325
|
+
const grid = this.geometry()
|
|
326
|
+
const list: number[] = []
|
|
327
|
+
for (let pitch = grid.safeHighest; pitch >= grid.safeLowest; pitch--) list.push(pitch)
|
|
328
|
+
return list
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
beatLines(): number[] {
|
|
332
|
+
return Array.from(
|
|
333
|
+
{ length: Math.max(0, this.geometry().computedBeats) + 1 },
|
|
334
|
+
(_v, beat) => beat,
|
|
335
|
+
)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
isC(pitch: number): boolean {
|
|
339
|
+
return ((pitch % 12) + 12) % 12 === 0
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
isBlackKey(pitch: number): boolean {
|
|
343
|
+
return isBlackKey(pitch)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
pitchLabel(pitch: number): string {
|
|
347
|
+
return pitchLabel(pitch)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
showsCursor(): boolean {
|
|
351
|
+
return !!this.onNoteAdd && this.gridFocused()
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
showsStatus(): boolean {
|
|
355
|
+
return !!this.onNoteAdd
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
setGridFocused(focused: boolean): void {
|
|
359
|
+
this.gridFocused.set(focused)
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
rollLabel(): string {
|
|
363
|
+
return this.i18n.t('pianoRoll.aria.roll', {}, { defaultValue: 'Piano roll' })
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
keysLabel(): string {
|
|
367
|
+
return this.i18n.t('pianoRoll.aria.keys', {}, { defaultValue: 'Piano keys' })
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
gridLabel(): string {
|
|
371
|
+
return this.i18n.t('pianoRoll.aria.grid', {}, { defaultValue: 'Note grid' })
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
gridHelpLabel(): string {
|
|
375
|
+
return this.i18n.t(
|
|
376
|
+
'pianoRoll.aria.gridHelp',
|
|
377
|
+
{},
|
|
378
|
+
{ defaultValue: 'The arrow keys move the cell cursor, Enter or Space paints a note at it.' },
|
|
379
|
+
)
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
resizeLabel(): string {
|
|
383
|
+
return this.i18n.t('pianoRoll.aria.resize', {}, { defaultValue: 'Resize note' })
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
cursorLabel(): string {
|
|
387
|
+
const cursor = this.cursor()
|
|
388
|
+
return this.i18n.t(
|
|
389
|
+
'pianoRoll.aria.cursor',
|
|
390
|
+
{ pitch: pitchLabel(cursor.pitch), beat: cursor.beat.toFixed(2) },
|
|
391
|
+
{ defaultValue: 'Cursor on {{pitch}} at beat {{beat}}' },
|
|
392
|
+
)
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
noteAria(note: MidiNote): string {
|
|
396
|
+
return this.i18n.t(
|
|
397
|
+
'pianoRoll.aria.note',
|
|
398
|
+
{
|
|
399
|
+
pitch: pitchLabel(note.pitch),
|
|
400
|
+
startBeat: note.startBeat.toFixed(2),
|
|
401
|
+
durationBeats: note.durationBeats.toFixed(2),
|
|
402
|
+
},
|
|
403
|
+
{ defaultValue: 'Note {{pitch}} starting at beat {{startBeat}} for {{durationBeats}} beats' },
|
|
404
|
+
)
|
|
405
|
+
}
|
|
406
|
+
// … truncated — 14 more members: keysColumnStyle, keyStyle, rowStyle, lineStyle, cursorStyle, gridSurfaceStyle, noteStyle, paintNoteAt, handleGridClick, handleGridKeyDown, handleNoteContextMenu, beginDrag, onMove, onUp; the full declaration is in node_modules/@molecule/app-feature-piano-roll-angular/dist/piano-roll.component.d.ts
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
_(Member comments are left out to fit; the full declaration is in `node_modules/@molecule/app-feature-piano-roll-angular/dist/piano-roll.component.d.ts`.)_
|
|
410
|
+
|
|
411
|
+
### Functions
|
|
412
|
+
|
|
413
|
+
#### `snapToBeats(snap)`
|
|
414
|
+
|
|
415
|
+
Convert a snap setting to its size in beats.
|
|
416
|
+
|
|
417
|
+
```typescript
|
|
418
|
+
function snapToBeats(snap: PianoRollSnap): number
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
- `snap` — Snap resolution.
|
|
422
|
+
|
|
423
|
+
**Returns:** Snap step size in beats.
|
|
424
|
+
|
|
425
|
+
#### `snapBeat(beat, snap)`
|
|
426
|
+
|
|
427
|
+
Snap a beat value to the nearest multiple of the snap step (rounding down).
|
|
428
|
+
|
|
429
|
+
```typescript
|
|
430
|
+
function snapBeat(beat: number, snap: PianoRollSnap): number
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
- `beat` — Raw beat value (may be fractional).
|
|
434
|
+
- `snap` — Snap resolution.
|
|
435
|
+
|
|
436
|
+
**Returns:** The floored snapped beat (>= 0).
|
|
437
|
+
|
|
438
|
+
#### `snapBeatRound(beat, snap)`
|
|
439
|
+
|
|
440
|
+
Round a beat value to the nearest snap step.
|
|
441
|
+
|
|
442
|
+
```typescript
|
|
443
|
+
function snapBeatRound(beat: number, snap: PianoRollSnap): number
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
- `beat` — Raw beat value (may be fractional).
|
|
447
|
+
- `snap` — Snap resolution.
|
|
448
|
+
|
|
449
|
+
**Returns:** The rounded snapped beat (>= 0).
|
|
450
|
+
|
|
451
|
+
#### `pixelsToBeats(pixels, pixelsPerBeat)`
|
|
452
|
+
|
|
453
|
+
Convert a pixel offset into beats given the horizontal scale.
|
|
454
|
+
|
|
455
|
+
```typescript
|
|
456
|
+
function pixelsToBeats(pixels: number, pixelsPerBeat: number): number
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
- `pixels` — Offset in pixels.
|
|
460
|
+
- `pixelsPerBeat` — Horizontal scale.
|
|
461
|
+
|
|
462
|
+
**Returns:** Beats represented by the offset (may be negative).
|
|
463
|
+
|
|
464
|
+
#### `beatsToPixels(beats, pixelsPerBeat)`
|
|
465
|
+
|
|
466
|
+
Convert a beat value into pixels given the horizontal scale.
|
|
467
|
+
|
|
468
|
+
```typescript
|
|
469
|
+
function beatsToPixels(beats: number, pixelsPerBeat: number): number
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
- `beats` — Beat value.
|
|
473
|
+
- `pixelsPerBeat` — Horizontal scale.
|
|
474
|
+
|
|
475
|
+
**Returns:** Pixel offset.
|
|
476
|
+
|
|
477
|
+
#### `yToPitch(y, noteHeight, highestPitch, lowestPitch)`
|
|
478
|
+
|
|
479
|
+
Convert a vertical pixel offset into a MIDI pitch. Higher pitches sit at the
|
|
480
|
+
top, so `y = 0` maps to `highestPitch`.
|
|
481
|
+
|
|
482
|
+
```typescript
|
|
483
|
+
function yToPitch(y: number, noteHeight: number, highestPitch: number, lowestPitch: number): number
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
- `y` — Vertical pixel offset from the top of the grid.
|
|
487
|
+
- `noteHeight` — Row height per pitch.
|
|
488
|
+
- `highestPitch` — Top-most pitch in the visible range.
|
|
489
|
+
- `lowestPitch` — Bottom-most pitch in the visible range.
|
|
490
|
+
|
|
491
|
+
**Returns:** A MIDI pitch clamped into `[lowestPitch, highestPitch]`.
|
|
492
|
+
|
|
493
|
+
#### `pitchToY(pitch, noteHeight, highestPitch)`
|
|
494
|
+
|
|
495
|
+
Convert a MIDI pitch into the vertical pixel offset of its row.
|
|
496
|
+
|
|
497
|
+
```typescript
|
|
498
|
+
function pitchToY(pitch: number, noteHeight: number, highestPitch: number): number
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
- `pitch` — MIDI pitch number.
|
|
502
|
+
- `noteHeight` — Row height per pitch.
|
|
503
|
+
- `highestPitch` — Top-most pitch in the visible range.
|
|
504
|
+
|
|
505
|
+
**Returns:** Vertical pixel offset for the pitch's row.
|
|
506
|
+
|
|
507
|
+
#### `isBlackKey(pitch)`
|
|
508
|
+
|
|
509
|
+
Determine whether a MIDI pitch corresponds to a black key on a piano
|
|
510
|
+
keyboard.
|
|
511
|
+
|
|
512
|
+
```typescript
|
|
513
|
+
function isBlackKey(pitch: number): boolean
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
- `pitch` — MIDI pitch number.
|
|
517
|
+
|
|
518
|
+
**Returns:** `true` if the pitch is a black key.
|
|
519
|
+
|
|
520
|
+
#### `pitchLabel(pitch)`
|
|
521
|
+
|
|
522
|
+
Format a MIDI pitch as a scientific-pitch-notation label.
|
|
523
|
+
|
|
524
|
+
```typescript
|
|
525
|
+
function pitchLabel(pitch: number): string
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
- `pitch` — MIDI pitch number.
|
|
529
|
+
|
|
530
|
+
**Returns:** Formatted label.
|
|
531
|
+
|
|
532
|
+
### Constants
|
|
533
|
+
|
|
534
|
+
#### `PIANO_KEYS_WIDTH_PX`
|
|
535
|
+
|
|
536
|
+
Pixel width of the leading piano-keys column.
|
|
537
|
+
|
|
538
|
+
```typescript
|
|
539
|
+
const PIANO_KEYS_WIDTH_PX: 56
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
#### `MIN_NOTE_DURATION_BEATS`
|
|
543
|
+
|
|
544
|
+
Minimum note duration in beats — notes can't be resized below this.
|
|
545
|
+
|
|
546
|
+
```typescript
|
|
547
|
+
const MIN_NOTE_DURATION_BEATS: number
|
|
548
|
+
```
|
|
549
|
+
|
|
550
|
+
#### `DRAG_DISTANCE_THRESHOLD_PX`
|
|
551
|
+
|
|
552
|
+
Pointer-distance threshold (px) before a press becomes a drag.
|
|
553
|
+
|
|
554
|
+
```typescript
|
|
555
|
+
const DRAG_DISTANCE_THRESHOLD_PX: 3
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
#### `DEFAULT_NOTE_VELOCITY`
|
|
559
|
+
|
|
560
|
+
Default MIDI velocity assigned to freshly-painted notes.
|
|
561
|
+
|
|
562
|
+
```typescript
|
|
563
|
+
const DEFAULT_NOTE_VELOCITY: 96
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
## Injection Notes
|
|
567
|
+
|
|
568
|
+
### Requirements
|
|
569
|
+
|
|
570
|
+
Peer dependencies:
|
|
571
|
+
|
|
572
|
+
- `@angular/common` ^22.0.0
|
|
573
|
+
- `@angular/core` ^22.0.0
|
|
574
|
+
- `@angular/platform-browser` ^22.0.0
|
|
575
|
+
- `@molecule/app-angular` ^3.5.0
|
|
576
|
+
- `@molecule/app-ui` ^1.0.1
|
|
577
|
+
- `@molecule/app-ui-angular` ^1.1.0
|
|
578
|
+
|
|
579
|
+
### Runtime Dependencies
|
|
580
|
+
|
|
581
|
+
- `@angular/common`
|
|
582
|
+
- `@angular/core`
|
|
583
|
+
- `@angular/platform-browser`
|
|
584
|
+
- `@molecule/app-angular`
|
|
585
|
+
- `@molecule/app-ui`
|
|
586
|
+
- `@molecule/app-ui-angular`
|
|
587
|
+
|
|
588
|
+
- Requires a bonded ClassMap (`cm.cn`, `cm.cursorPointer`, …) — rendering
|
|
589
|
+
throws otherwise. No router dependency.
|
|
590
|
+
- The host IS React's root `<div>` (`div[mol-piano-roll]`).
|
|
591
|
+
- Every visible string comes from `useTranslation()` (`pianoRoll.aria.*`)
|
|
592
|
+
via the companion `@molecule/app-locales-feature-piano-roll` locale bond,
|
|
593
|
+
so a locale switch re-renders it.
|
|
594
|
+
- The grid is focusable and paints from the keyboard (arrow keys move the
|
|
595
|
+
cell cursor, Enter / Space paints), exactly as React's.
|
|
596
|
+
|
|
597
|
+
## Translations
|
|
598
|
+
|
|
599
|
+
Translation strings are provided by `@molecule/app-locales-feature-piano-roll`.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure geometry helpers and constants of the Angular piano roll — the same values
|
|
3
|
+
* and the same math as `@molecule/app-feature-piano-roll-react`, so the helper
|
|
4
|
+
* exports every framework must reproduce by value are identical.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { PianoRollSnap } from './types.js';
|
|
9
|
+
/** Pixel width of the leading piano-keys column. */
|
|
10
|
+
export declare const PIANO_KEYS_WIDTH_PX = 56;
|
|
11
|
+
/** Minimum note duration in beats — notes can't be resized below this. */
|
|
12
|
+
export declare const MIN_NOTE_DURATION_BEATS: number;
|
|
13
|
+
/** Pointer-distance threshold (px) before a press becomes a drag. */
|
|
14
|
+
export declare const DRAG_DISTANCE_THRESHOLD_PX = 3;
|
|
15
|
+
/** Default MIDI velocity assigned to freshly-painted notes. */
|
|
16
|
+
export declare const DEFAULT_NOTE_VELOCITY = 96;
|
|
17
|
+
/**
|
|
18
|
+
* Convert a snap setting to its size in beats.
|
|
19
|
+
*
|
|
20
|
+
* @param snap - Snap resolution.
|
|
21
|
+
* @returns Snap step size in beats.
|
|
22
|
+
*/
|
|
23
|
+
export declare function snapToBeats(snap: PianoRollSnap): number;
|
|
24
|
+
/**
|
|
25
|
+
* Snap a beat value to the nearest multiple of the snap step (rounding down).
|
|
26
|
+
*
|
|
27
|
+
* @param beat - Raw beat value (may be fractional).
|
|
28
|
+
* @param snap - Snap resolution.
|
|
29
|
+
* @returns The floored snapped beat (>= 0).
|
|
30
|
+
*/
|
|
31
|
+
export declare function snapBeat(beat: number, snap: PianoRollSnap): number;
|
|
32
|
+
/**
|
|
33
|
+
* Round a beat value to the nearest snap step.
|
|
34
|
+
*
|
|
35
|
+
* @param beat - Raw beat value (may be fractional).
|
|
36
|
+
* @param snap - Snap resolution.
|
|
37
|
+
* @returns The rounded snapped beat (>= 0).
|
|
38
|
+
*/
|
|
39
|
+
export declare function snapBeatRound(beat: number, snap: PianoRollSnap): number;
|
|
40
|
+
/**
|
|
41
|
+
* Convert a pixel offset into beats given the horizontal scale.
|
|
42
|
+
*
|
|
43
|
+
* @param pixels - Offset in pixels.
|
|
44
|
+
* @param pixelsPerBeat - Horizontal scale.
|
|
45
|
+
* @returns Beats represented by the offset (may be negative).
|
|
46
|
+
*/
|
|
47
|
+
export declare function pixelsToBeats(pixels: number, pixelsPerBeat: number): number;
|
|
48
|
+
/**
|
|
49
|
+
* Convert a beat value into pixels given the horizontal scale.
|
|
50
|
+
*
|
|
51
|
+
* @param beats - Beat value.
|
|
52
|
+
* @param pixelsPerBeat - Horizontal scale.
|
|
53
|
+
* @returns Pixel offset.
|
|
54
|
+
*/
|
|
55
|
+
export declare function beatsToPixels(beats: number, pixelsPerBeat: number): number;
|
|
56
|
+
/**
|
|
57
|
+
* Convert a vertical pixel offset into a MIDI pitch. Higher pitches sit at the
|
|
58
|
+
* top, so `y = 0` maps to `highestPitch`.
|
|
59
|
+
*
|
|
60
|
+
* @param y - Vertical pixel offset from the top of the grid.
|
|
61
|
+
* @param noteHeight - Row height per pitch.
|
|
62
|
+
* @param highestPitch - Top-most pitch in the visible range.
|
|
63
|
+
* @param lowestPitch - Bottom-most pitch in the visible range.
|
|
64
|
+
* @returns A MIDI pitch clamped into `[lowestPitch, highestPitch]`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function yToPitch(y: number, noteHeight: number, highestPitch: number, lowestPitch: number): number;
|
|
67
|
+
/**
|
|
68
|
+
* Convert a MIDI pitch into the vertical pixel offset of its row.
|
|
69
|
+
*
|
|
70
|
+
* @param pitch - MIDI pitch number.
|
|
71
|
+
* @param noteHeight - Row height per pitch.
|
|
72
|
+
* @param highestPitch - Top-most pitch in the visible range.
|
|
73
|
+
* @returns Vertical pixel offset for the pitch's row.
|
|
74
|
+
*/
|
|
75
|
+
export declare function pitchToY(pitch: number, noteHeight: number, highestPitch: number): number;
|
|
76
|
+
/**
|
|
77
|
+
* Determine whether a MIDI pitch corresponds to a black key on a piano
|
|
78
|
+
* keyboard.
|
|
79
|
+
*
|
|
80
|
+
* @param pitch - MIDI pitch number.
|
|
81
|
+
* @returns `true` if the pitch is a black key.
|
|
82
|
+
*/
|
|
83
|
+
export declare function isBlackKey(pitch: number): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Format a MIDI pitch as a scientific-pitch-notation label.
|
|
86
|
+
*
|
|
87
|
+
* @param pitch - MIDI pitch number.
|
|
88
|
+
* @returns Formatted label.
|
|
89
|
+
*/
|
|
90
|
+
export declare function pitchLabel(pitch: number): string;
|
|
91
|
+
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,oDAAoD;AACpD,eAAO,MAAM,mBAAmB,KAAK,CAAA;AAErC,0EAA0E;AAC1E,eAAO,MAAM,uBAAuB,QAAS,CAAA;AAE7C,qEAAqE;AACrE,eAAO,MAAM,0BAA0B,IAAI,CAAA;AAE3C,+DAA+D;AAC/D,eAAO,MAAM,qBAAqB,KAAK,CAAA;AAQvC;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CAevD;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,MAAM,CAMlE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,GAAG,MAAM,CAMvE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAG3E;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAG1E;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CACtB,CAAC,EAAE,MAAM,EACT,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,GAClB,MAAM,CAOR;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,CAExF;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGjD;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKhD"}
|