solid-pianoroll 0.0.21 → 0.0.23
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/dist/cjs/index.js +504 -371
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +506 -373
- package/dist/esm/index.js.map +1 -1
- package/dist/source/PianoRoll.jsx +50 -63
- package/dist/source/PianoRollGrid.jsx +22 -46
- package/dist/source/PianoRollKeys.jsx +10 -21
- package/dist/source/PianoRollNotes.jsx +93 -110
- package/dist/source/PianoRollNotesScroller.jsx +16 -0
- package/dist/source/PianoRollScale.jsx +29 -0
- package/dist/source/PianoRollScrollZoomViewPort.jsx +49 -0
- package/dist/source/PianoRollTrackList.jsx +2 -3
- package/dist/source/PianoRollTrackListScroller.jsx +16 -0
- package/dist/source/index.jsx +1 -1
- package/dist/source/usePianoRollGrid.js +45 -0
- package/dist/source/usePianoRollState.js +19 -5
- package/dist/source/{PlayHead.jsx → viewport/PlayHead.jsx} +11 -12
- package/dist/source/viewport/ScrollZoomContainer.jsx +2 -2
- package/dist/source/viewport/ZoomSliderControl.jsx +4 -1
- package/dist/types/PianoRollContext.d.ts +26 -12
- package/dist/types/PianoRollNotesScroller.d.ts +3 -0
- package/dist/types/PianoRollScale.d.ts +2 -0
- package/dist/types/PianoRollScrollZoomViewPort.d.ts +3 -0
- package/dist/types/PianoRollTrackListScroller.d.ts +3 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/usePianoRollGrid.d.ts +13 -0
- package/dist/types/usePianoRollState.d.ts +14 -6
- package/dist/types/{PlayHead.d.ts → viewport/PlayHead.d.ts} +3 -3
- package/package.json +1 -1
|
@@ -1,90 +1,77 @@
|
|
|
1
1
|
import styles from "./PianoRoll.module.css";
|
|
2
|
-
import {
|
|
2
|
+
import { Show, mergeProps } from "solid-js";
|
|
3
3
|
import { PianoRollContextProvider, splitContextProps } from "./PianoRollContext";
|
|
4
4
|
import PianoRollKeys from "./PianoRollKeys";
|
|
5
5
|
import PianoRollNotes from "./PianoRollNotes";
|
|
6
|
-
import ScrollZoomContainer from "./viewport/ScrollZoomContainer";
|
|
7
6
|
import PianoRollGrid from "./PianoRollGrid";
|
|
8
|
-
import { ScrollZoomViewPort as ScrollZoomViewPort } from "./viewport/ScrollZoomViewPort";
|
|
9
|
-
import useBoundingClientRect from "./useBoundingClientRect";
|
|
10
7
|
import ZoomSliderControl from "./viewport/ZoomSliderControl";
|
|
11
8
|
import PianoRollTrackList from "./PianoRollTrackList";
|
|
9
|
+
import PianoRollScrollZoomViewPort from "./PianoRollScrollZoomViewPort";
|
|
10
|
+
import PianoRollNotesScroller from "./PianoRollNotesScroller";
|
|
11
|
+
import PianoRollTrackListScroller from "./PianoRollTrackListScroller";
|
|
12
|
+
import PianoRollScale from "./PianoRollScale";
|
|
12
13
|
const PianoRoll = (allProps) => {
|
|
13
14
|
const propsWithDefaults = mergeProps({ showAllTracks: false }, allProps);
|
|
14
15
|
const [context, divProps] = splitContextProps(propsWithDefaults);
|
|
15
|
-
const [notesScrollerRef, setNotesScrollerRef] = createSignal();
|
|
16
|
-
const [tracksScrollerRef, setTracksScrollerRef] = createSignal();
|
|
17
|
-
const notesScrollerClientRect = useBoundingClientRect(notesScrollerRef);
|
|
18
|
-
const tracksScrollerClientRect = useBoundingClientRect(tracksScrollerRef);
|
|
19
|
-
const zoomFactor = 500;
|
|
20
16
|
return (<PianoRollContextProvider value={context}>
|
|
21
17
|
<div {...divProps} class={styles.PianoRoll}>
|
|
22
|
-
<
|
|
23
|
-
horizontal: () => ({
|
|
24
|
-
pixelOffset: notesScrollerClientRect().left,
|
|
25
|
-
pixelSize: notesScrollerClientRect().width,
|
|
26
|
-
position: context.position,
|
|
27
|
-
range: context.duration,
|
|
28
|
-
zoom: context.zoom * (zoomFactor / notesScrollerClientRect().width),
|
|
29
|
-
onPositionChange: context.onPositionChange,
|
|
30
|
-
onZoomChange: (zoom) => context.onZoomChange?.(zoom / (zoomFactor / notesScrollerClientRect().width)),
|
|
31
|
-
minZoom: 1,
|
|
32
|
-
maxZoom: 500,
|
|
33
|
-
}),
|
|
34
|
-
vertical: () => ({
|
|
35
|
-
pixelOffset: notesScrollerClientRect().top,
|
|
36
|
-
pixelSize: notesScrollerClientRect().height,
|
|
37
|
-
position: context.verticalPosition,
|
|
38
|
-
range: 128,
|
|
39
|
-
zoom: context.verticalZoom * (zoomFactor / notesScrollerClientRect().height),
|
|
40
|
-
onPositionChange: context.onVerticalPositionChange,
|
|
41
|
-
onZoomChange: (verticalZoom) => context.onVerticalZoomChange?.(verticalZoom / (zoomFactor / notesScrollerClientRect().height)),
|
|
42
|
-
minZoom: 1,
|
|
43
|
-
maxZoom: 10,
|
|
44
|
-
}),
|
|
45
|
-
horizontalTracks: () => ({
|
|
46
|
-
pixelOffset: 0,
|
|
47
|
-
pixelSize: tracksScrollerClientRect().width,
|
|
48
|
-
}),
|
|
49
|
-
verticalTracks: () => ({
|
|
50
|
-
pixelOffset: tracksScrollerClientRect().top,
|
|
51
|
-
pixelSize: tracksScrollerClientRect().height,
|
|
52
|
-
position: context.verticalTrackPosition,
|
|
53
|
-
range: context.tracks.length,
|
|
54
|
-
zoom: context.verticalTrackZoom * (zoomFactor / tracksScrollerClientRect().height),
|
|
55
|
-
onPositionChange: context.onVerticalTrackPositionChange,
|
|
56
|
-
onZoomChange: (verticalTrackZoom) => context.onVerticalTrackZoomChange?.(verticalTrackZoom / (zoomFactor / tracksScrollerClientRect().height)),
|
|
57
|
-
minZoom: 0.8,
|
|
58
|
-
maxZoom: 3,
|
|
59
|
-
}),
|
|
60
|
-
horizontalKeys: () => ({ pixelSize: 60 }),
|
|
61
|
-
}}>
|
|
18
|
+
<PianoRollScrollZoomViewPort>
|
|
62
19
|
<div class={styles.PianoRollContainer}>
|
|
63
20
|
<ZoomSliderControl orientation="vertical" dimensionName="verticalTracks"/>
|
|
64
|
-
<div
|
|
21
|
+
<div classList={{
|
|
22
|
+
[styles.PianoRollLeftColumn]: true,
|
|
23
|
+
[styles.showTrackList]: context.showTrackList,
|
|
24
|
+
}}>
|
|
65
25
|
<Show when={context.showTrackList}>
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
26
|
+
<div style={{
|
|
27
|
+
height: "30px",
|
|
28
|
+
}}>
|
|
29
|
+
<button title={context.mode === "keys" ? "Tracks Mode" : "Keys Mode"} onClick={() => context.onModeChange(context.mode === "keys" ? "tracks" : "keys")} style={{
|
|
30
|
+
"font-size": "16px",
|
|
31
|
+
"line-height": "16px",
|
|
32
|
+
cursor: "pointer",
|
|
33
|
+
overflow: "hidden",
|
|
34
|
+
}}>
|
|
35
|
+
<div>{context.mode === "keys" ? "≡" : "🎹"}</div>
|
|
36
|
+
</button>
|
|
37
|
+
</div>
|
|
72
38
|
</Show>
|
|
39
|
+
<div style={{ flex: 1, display: "flex", overflow: "hidden" }}>
|
|
40
|
+
<Show when={context.showTrackList}>
|
|
41
|
+
<PianoRollTrackListScroller>
|
|
42
|
+
<PianoRollTrackList />
|
|
43
|
+
</PianoRollTrackListScroller>
|
|
44
|
+
</Show>
|
|
45
|
+
<Show when={context.mode === "keys"}>
|
|
46
|
+
<PianoRollKeys />
|
|
47
|
+
</Show>
|
|
48
|
+
</div>
|
|
73
49
|
</div>
|
|
74
50
|
|
|
75
|
-
<
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
51
|
+
<div style={{
|
|
52
|
+
width: "100%",
|
|
53
|
+
display: "flex",
|
|
54
|
+
height: "100%",
|
|
55
|
+
"flex-direction": "column",
|
|
56
|
+
overflow: "hidden",
|
|
57
|
+
}}>
|
|
58
|
+
<div style={{ height: "30px" }}>
|
|
59
|
+
<PianoRollScale />
|
|
60
|
+
</div>
|
|
61
|
+
<PianoRollNotesScroller>
|
|
62
|
+
{allProps.children}
|
|
63
|
+
<PianoRollGrid />
|
|
64
|
+
<PianoRollNotes />
|
|
65
|
+
</PianoRollNotesScroller>
|
|
66
|
+
</div>
|
|
80
67
|
|
|
81
68
|
<ZoomSliderControl orientation="vertical" disabled={context.mode !== "keys"}/>
|
|
82
69
|
</div>
|
|
83
70
|
<ZoomSliderControl orientation="horizontal" style={{
|
|
84
|
-
"margin-left": `${tracksScrollerClientRect
|
|
71
|
+
"margin-left": `${context.tracksScrollerClientRect.width + 24}px`,
|
|
85
72
|
"margin-right": "24px",
|
|
86
73
|
}}/>
|
|
87
|
-
</
|
|
74
|
+
</PianoRollScrollZoomViewPort>
|
|
88
75
|
</div>
|
|
89
76
|
</PianoRollContextProvider>);
|
|
90
77
|
};
|
|
@@ -3,49 +3,23 @@ import { usePianoRollContext } from "./PianoRollContext";
|
|
|
3
3
|
import { blackKeys, keys } from "./PianoRollKeys";
|
|
4
4
|
import { useViewPortDimension } from "./viewport/ScrollZoomViewPort";
|
|
5
5
|
import styles from "./PianoRollGrid.module.css";
|
|
6
|
+
import usePianoRollGrid from "./usePianoRollGrid";
|
|
6
7
|
const PianoRollGrid = () => {
|
|
7
8
|
const context = usePianoRollContext();
|
|
8
9
|
const verticalViewPort = createMemo(() => useViewPortDimension(context.mode === "keys" ? "vertical" : "verticalTracks"));
|
|
9
10
|
const horizontalViewPort = createMemo(() => useViewPortDimension("horizontal"));
|
|
10
|
-
const
|
|
11
|
-
const selectedGridDivisorTicks = createMemo(() => measureTicks() / context.gridDivision);
|
|
12
|
-
function calculateVisibleGridDivisorTicks(value) {
|
|
13
|
-
const visibleRange = horizontalViewPort().calculateVisibleRange();
|
|
14
|
-
if (visibleRange <= 0)
|
|
15
|
-
return 0;
|
|
16
|
-
if (visibleRange / value > 100) {
|
|
17
|
-
return calculateVisibleGridDivisorTicks(value * 2);
|
|
18
|
-
}
|
|
19
|
-
if (visibleRange / value < 30) {
|
|
20
|
-
return calculateVisibleGridDivisorTicks(value / 2);
|
|
21
|
-
}
|
|
22
|
-
return value;
|
|
23
|
-
}
|
|
24
|
-
const gridDivisorTicks = createMemo(() => calculateVisibleGridDivisorTicks(selectedGridDivisorTicks()));
|
|
25
|
-
const gridArray = createMemo(() => {
|
|
26
|
-
const numberOfLines = Math.ceil(horizontalViewPort().calculateVisibleRange() / gridDivisorTicks() + 1);
|
|
27
|
-
const startIndex = Math.floor(context.position / gridDivisorTicks());
|
|
28
|
-
return Array.from({ length: numberOfLines }).map((_, index) => ({
|
|
29
|
-
index: index + startIndex,
|
|
30
|
-
ticks: (index + startIndex) * gridDivisorTicks(),
|
|
31
|
-
}));
|
|
32
|
-
});
|
|
11
|
+
const gridArray = usePianoRollGrid();
|
|
33
12
|
return (<div class={styles.PianoRollGrid}>
|
|
34
13
|
<Index each={gridArray()}>
|
|
35
14
|
{(entry) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
left: `${virtualDimensions().offset}px`,
|
|
45
|
-
width: `${virtualDimensions().size}px`,
|
|
46
|
-
"border-left-color": (entry().index * gridDivisorTicks()) % selectedGridDivisorTicks() === 0
|
|
47
|
-
? "gray"
|
|
48
|
-
: "#bbb",
|
|
15
|
+
return (<Show when={horizontalViewPort().isVisible(entry().virtualDimensions)}>
|
|
16
|
+
<div classList={{
|
|
17
|
+
[styles["PianoRollGrid-Time"]]: true,
|
|
18
|
+
[styles["Highlighted"]]: entry().isHighlighted,
|
|
19
|
+
[styles["HighlightedBorder"]]: entry().hasHighlightedBorder,
|
|
20
|
+
}} style={{
|
|
21
|
+
left: `${entry().virtualDimensions.offset}px`,
|
|
22
|
+
width: `${entry().virtualDimensions.size}px`,
|
|
49
23
|
}}></div>
|
|
50
24
|
</Show>);
|
|
51
25
|
}}
|
|
@@ -54,13 +28,15 @@ const PianoRollGrid = () => {
|
|
|
54
28
|
<Index each={keys}>
|
|
55
29
|
{(key) => {
|
|
56
30
|
const virtualDimensions = createMemo(() => verticalViewPort().calculatePixelDimensions(127 - key().number, 1));
|
|
57
|
-
return (<Show when={virtualDimensions()
|
|
58
|
-
<div
|
|
31
|
+
return (<Show when={verticalViewPort().isVisible(virtualDimensions())}>
|
|
32
|
+
<div classList={{
|
|
33
|
+
[styles["PianoRollGrid-Row"]]: true,
|
|
34
|
+
[styles["Key"]]: true,
|
|
35
|
+
[styles["IsDark"]]: key().isBlack,
|
|
36
|
+
[styles["IsBlackAndNextIsWhite"]]: !key().isBlack && !blackKeys.includes((key().number + 1) % 12),
|
|
37
|
+
}} style={{
|
|
59
38
|
top: `${virtualDimensions().offset}px`,
|
|
60
39
|
height: `${virtualDimensions().size}px`,
|
|
61
|
-
width: "100%",
|
|
62
|
-
"background-color": key().isBlack ? "rgba(0,0,0,0.2)" : "none",
|
|
63
|
-
"border-width": `${!key().isBlack && !blackKeys.includes((key().number + 1) % 12) ? "0.1px" : 0} 1px ${!key().isBlack && !blackKeys.includes((key().number - 1) % 12) ? "0.1px" : 0} 0`,
|
|
64
40
|
}}></div>
|
|
65
41
|
</Show>);
|
|
66
42
|
}}
|
|
@@ -71,13 +47,13 @@ const PianoRollGrid = () => {
|
|
|
71
47
|
<For each={context.tracks}>
|
|
72
48
|
{(track, index) => {
|
|
73
49
|
const virtualDimensions = createMemo(() => verticalViewPort().calculatePixelDimensions(index(), 1));
|
|
74
|
-
return (<Show when={virtualDimensions()
|
|
75
|
-
<div
|
|
50
|
+
return (<Show when={verticalViewPort().isVisible(virtualDimensions())}>
|
|
51
|
+
<div classList={{
|
|
52
|
+
[styles["PianoRollGrid-Row"]]: true,
|
|
53
|
+
[styles["IsDark"]]: index() % 2 === 0,
|
|
54
|
+
}} style={{
|
|
76
55
|
top: `${virtualDimensions().offset}px`,
|
|
77
56
|
height: `${virtualDimensions().size}px`,
|
|
78
|
-
width: "100%",
|
|
79
|
-
"background-color": index() % 2 === 0 ? "rgba(0,0,0,0.2)" : "none",
|
|
80
|
-
"border-width": 0,
|
|
81
57
|
}}></div>
|
|
82
58
|
</Show>);
|
|
83
59
|
}}
|
|
@@ -23,11 +23,11 @@ const PianoRollKeys = () => {
|
|
|
23
23
|
<ScrollZoomContainer horizontalDimensionName="horizontalKeys" showScrollbar={false}>
|
|
24
24
|
<Index each={keys}>
|
|
25
25
|
{(key) => {
|
|
26
|
-
const isDown = createMemo(() => context.
|
|
26
|
+
const isDown = createMemo(() => context.isKeyDown(context.selectedTrackIndex, key().number));
|
|
27
27
|
const virtualDimensions = createMemo(() => verticalViewPort().calculatePixelDimensions(127 - key().number, 1));
|
|
28
28
|
const previousIsBlack = blackKeys.includes((key().number - 1) % 12);
|
|
29
29
|
const nextIsBlack = blackKeys.includes((key().number + 1) % 12);
|
|
30
|
-
return (<Show when={virtualDimensions()
|
|
30
|
+
return (<Show when={verticalViewPort().isVisible(virtualDimensions())}>
|
|
31
31
|
<div classList={{
|
|
32
32
|
[styles["Key"]]: true,
|
|
33
33
|
[styles["black"]]: key().isBlack,
|
|
@@ -35,38 +35,27 @@ const PianoRollKeys = () => {
|
|
|
35
35
|
[styles["down"]]: isDown(),
|
|
36
36
|
}} onMouseDown={() => {
|
|
37
37
|
setIsMouseDown(true);
|
|
38
|
-
context.onNoteDown(key().number);
|
|
38
|
+
context.onNoteDown(context.selectedTrackIndex, key().number);
|
|
39
39
|
}} onMouseUp={() => {
|
|
40
|
-
context.onNoteUp(key().number);
|
|
40
|
+
context.onNoteUp(context.selectedTrackIndex, key().number);
|
|
41
41
|
}} onMouseEnter={() => {
|
|
42
42
|
if (isMouseDown()) {
|
|
43
|
-
context.onNoteDown(key().number);
|
|
43
|
+
context.onNoteDown(context.selectedTrackIndex, key().number);
|
|
44
44
|
}
|
|
45
45
|
}} onMouseLeave={() => {
|
|
46
46
|
if (isMouseDown()) {
|
|
47
|
-
context.onNoteUp(key().number);
|
|
47
|
+
context.onNoteUp(context.selectedTrackIndex, key().number);
|
|
48
48
|
}
|
|
49
49
|
}} title={key().name} data-index={key().number % 12} style={{
|
|
50
50
|
top: `${virtualDimensions().offset -
|
|
51
|
-
(!key().isBlack
|
|
51
|
+
virtualDimensions().size * (!key().isBlack ? (nextIsBlack ? 1 / 2 : 0) : 0)}px`,
|
|
52
52
|
height: `${virtualDimensions().size +
|
|
53
53
|
(!key().isBlack && nextIsBlack ? virtualDimensions().size / 2 : 0) +
|
|
54
54
|
(!key().isBlack && previousIsBlack ? virtualDimensions().size / 2 : 0)}px`,
|
|
55
|
-
"box-shadow":
|
|
56
|
-
`0px 0px ${Math.min(virtualDimensions().size /
|
|
57
|
-
|
|
58
|
-
`0px 0px ${Math.min(virtualDimensions().size / 8, 2)}px ${Math.min(virtualDimensions().size / 20, 2)}px rgba(0, 0, 0, 0.5) inset`,
|
|
59
|
-
]
|
|
60
|
-
.filter((item) => !!item)
|
|
61
|
-
.join(", "),
|
|
62
|
-
}}>
|
|
63
|
-
<Show when={key().isBlack && false}>
|
|
64
|
-
<div class={styles["black-separator"]} style={{
|
|
65
|
-
top: `${virtualDimensions().offset}px`,
|
|
66
|
-
height: `${virtualDimensions().size / 2 - 0.25}px`,
|
|
55
|
+
"box-shadow": `0px 0px ${Math.min(virtualDimensions().size / 20, 1)}px ${Math.min(virtualDimensions().size / 50, 1)}px rgba(0, 0, 0, 0.5) ${key().isBlack ? "" : "inset"}` + isDown()
|
|
56
|
+
? `0px 0px ${Math.min(virtualDimensions().size / 8, 2)}px ${Math.min(virtualDimensions().size / 20, 2)}px rgba(0, 0, 0, 0.5) inset`
|
|
57
|
+
: "",
|
|
67
58
|
}}></div>
|
|
68
|
-
</Show>
|
|
69
|
-
</div>
|
|
70
59
|
</Show>);
|
|
71
60
|
}}
|
|
72
61
|
</Index>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createMemo, createSignal, For, Show } from "solid-js";
|
|
2
2
|
import { usePianoRollContext } from "./PianoRollContext";
|
|
3
3
|
import { useViewPortDimension } from "./viewport/ScrollZoomViewPort";
|
|
4
4
|
import styles from "./PianoRollNotes.module.scss";
|
|
@@ -8,73 +8,104 @@ const PianoRollNotes = (props) => {
|
|
|
8
8
|
const verticalViewPort = createMemo(() => useViewPortDimension(context.mode === "keys" ? "vertical" : "verticalTracks"));
|
|
9
9
|
const horizontalViewPort = createMemo(() => useViewPortDimension("horizontal"));
|
|
10
10
|
const gridDivisionTicks = createMemo(() => (context.ppq * 4) / context.gridDivision);
|
|
11
|
+
const [isDragging, setIsDragging] = createSignal(false);
|
|
12
|
+
const [noteDragMode, setNoteDragMode] = createSignal();
|
|
13
|
+
const [currentNoteIndex, setCurrentNoteIndex] = createSignal(-1);
|
|
14
|
+
const [currentNoteTrackIndex, setCurrentNoteTrackIndex] = createSignal(-1);
|
|
15
|
+
const [diffPosition, setDiffPosition] = createSignal(0);
|
|
16
|
+
const [getInitialNote, setInitialNote] = createSignal();
|
|
11
17
|
const snapValueToGridIfEnabled = (value, altKey) => context.snapToGrid && !altKey
|
|
12
18
|
? Math.round(value / gridDivisionTicks()) * gridDivisionTicks()
|
|
13
19
|
: value;
|
|
14
|
-
const
|
|
15
|
-
const position = horizontalViewPort().calculatePosition(event.clientX);
|
|
16
|
-
const existingNote = currentNote();
|
|
17
|
-
const midi = context.mode === "keys"
|
|
18
|
-
? 127 - Math.floor(verticalViewPort().calculatePosition(event.clientY))
|
|
19
|
-
: existingNote?.midi ?? 60;
|
|
20
|
+
const calculateNoteDragValues = (event) => {
|
|
20
21
|
const targetTrackIndex = context.mode === "tracks"
|
|
21
22
|
? clamp(Math.floor(verticalViewPort().calculatePosition(event.clientY)), 0, context.tracks.length - 1)
|
|
22
|
-
:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
23
|
+
: currentNoteTrackIndex() > -1
|
|
24
|
+
? currentNoteTrackIndex()
|
|
25
|
+
: context.selectedTrackIndex;
|
|
26
|
+
const midi = context.mode === "keys"
|
|
27
|
+
? Math.floor(128 - verticalViewPort().calculatePosition(event.clientY))
|
|
28
|
+
: getInitialNote()?.midi ?? 60;
|
|
29
|
+
const horiontalPosition = horizontalViewPort().calculatePosition(event.clientX);
|
|
30
|
+
return {
|
|
31
|
+
targetTrackIndex,
|
|
32
|
+
midi,
|
|
33
|
+
horiontalPosition,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const handleMouseMove = (mouseMoveEvent) => {
|
|
37
|
+
mouseMoveEvent.preventDefault();
|
|
38
|
+
mouseMoveEvent.stopPropagation();
|
|
39
|
+
const note = getInitialNote();
|
|
40
|
+
if (!note)
|
|
41
|
+
return;
|
|
42
|
+
const { targetTrackIndex, midi, horiontalPosition } = calculateNoteDragValues(mouseMoveEvent);
|
|
43
|
+
const ticks = snapValueToGridIfEnabled(horiontalPosition - diffPosition(), mouseMoveEvent.altKey);
|
|
44
|
+
const updatedNote = {
|
|
45
|
+
...note,
|
|
46
|
+
midi,
|
|
47
|
+
...(noteDragMode() === "move" && { ticks }),
|
|
48
|
+
...(noteDragMode() === "trimStart" && {
|
|
49
|
+
ticks: ticks < note.ticks + note.durationTicks ? ticks : note.ticks + note.durationTicks,
|
|
50
|
+
durationTicks: ticks < note.ticks + note.durationTicks
|
|
51
|
+
? note.ticks + note.durationTicks - ticks
|
|
52
|
+
: snapValueToGridIfEnabled(horiontalPosition - note.ticks, mouseMoveEvent.altKey),
|
|
53
|
+
}),
|
|
54
|
+
...(noteDragMode() === "trimEnd" && {
|
|
55
|
+
ticks: ticks < note.ticks ? ticks : note.ticks,
|
|
56
|
+
durationTicks: ticks < note.ticks
|
|
57
|
+
? note.ticks - ticks
|
|
58
|
+
: snapValueToGridIfEnabled(horiontalPosition - note.ticks, mouseMoveEvent.altKey),
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
const previousTrackIndex = currentNoteTrackIndex();
|
|
62
|
+
const previousNoteIndex = currentNoteIndex();
|
|
63
|
+
if (targetTrackIndex === previousTrackIndex) {
|
|
64
|
+
context.onNoteChange?.(previousTrackIndex, previousNoteIndex, updatedNote);
|
|
33
65
|
}
|
|
34
66
|
else {
|
|
35
|
-
|
|
67
|
+
if (context.onInsertNote) {
|
|
68
|
+
context.onRemoveNote?.(previousTrackIndex, previousNoteIndex);
|
|
69
|
+
const newNoteIndex = context.onInsertNote(targetTrackIndex, updatedNote);
|
|
70
|
+
setCurrentNoteTrackIndex(targetTrackIndex);
|
|
71
|
+
setCurrentNoteIndex(newNoteIndex);
|
|
72
|
+
}
|
|
36
73
|
}
|
|
37
74
|
};
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
75
|
+
const stopDragging = () => {
|
|
76
|
+
window.removeEventListener("mousemove", handleMouseMove);
|
|
77
|
+
window.removeEventListener("mouseup", stopDragging);
|
|
78
|
+
setIsDragging(false);
|
|
79
|
+
setCurrentNoteIndex(-1);
|
|
80
|
+
setCurrentNoteTrackIndex(-1);
|
|
81
|
+
};
|
|
82
|
+
const startDragging = () => {
|
|
83
|
+
window.addEventListener("mousemove", handleMouseMove);
|
|
84
|
+
window.addEventListener("mouseup", stopDragging);
|
|
85
|
+
};
|
|
44
86
|
const getClasses = (noteDragMode) => {
|
|
45
87
|
return noteDragMode ? [styles.Note, styles[noteDragMode]] : [styles.Note];
|
|
46
88
|
};
|
|
47
|
-
return (<div classList={{ [styles.PianoRollNotes]: true }} ref={props.ref} onMouseDown={(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
setCurrentNoteIndex(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
insertOrUpdateNote(event);
|
|
68
|
-
}} onDblClick={(event) => {
|
|
69
|
-
insertOrUpdateNote(event);
|
|
70
|
-
}} onClick={(event) => {
|
|
71
|
-
if (currentNote()) {
|
|
72
|
-
setCurrentNoteIndex(-1);
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
if (!event.altKey)
|
|
76
|
-
return;
|
|
77
|
-
insertOrUpdateNote(event);
|
|
89
|
+
return (<div classList={{ [styles.PianoRollNotes]: true }} ref={props.ref} onMouseDown={(mouseDownEvent) => {
|
|
90
|
+
mouseDownEvent.preventDefault();
|
|
91
|
+
mouseDownEvent.stopPropagation();
|
|
92
|
+
const { targetTrackIndex, midi, horiontalPosition } = calculateNoteDragValues(mouseDownEvent);
|
|
93
|
+
const ticks = snapValueToGridIfEnabled(horiontalPosition, mouseDownEvent.altKey);
|
|
94
|
+
const durationTicks = gridDivisionTicks();
|
|
95
|
+
const newNote = {
|
|
96
|
+
midi,
|
|
97
|
+
ticks,
|
|
98
|
+
durationTicks,
|
|
99
|
+
velocity: 100,
|
|
100
|
+
};
|
|
101
|
+
const newNoteIndex = context.onInsertNote(targetTrackIndex, newNote);
|
|
102
|
+
setIsDragging(true);
|
|
103
|
+
setCurrentNoteTrackIndex(targetTrackIndex);
|
|
104
|
+
setCurrentNoteIndex(newNoteIndex);
|
|
105
|
+
setInitialNote(newNote);
|
|
106
|
+
setDiffPosition(0);
|
|
107
|
+
setNoteDragMode("trimEnd");
|
|
108
|
+
startDragging();
|
|
78
109
|
}}>
|
|
79
110
|
<For each={context.tracks}>
|
|
80
111
|
{(track, trackIndex) => {
|
|
@@ -104,63 +135,15 @@ const PianoRollNotes = (props) => {
|
|
|
104
135
|
context.onRemoveNote?.(trackIndex(), noteIndex());
|
|
105
136
|
}} onMouseDown={(event) => {
|
|
106
137
|
event.stopPropagation();
|
|
138
|
+
const initialPosition = horizontalViewPort().calculatePosition(event.clientX);
|
|
139
|
+
setDiffPosition(noteDragMode() === "trimEnd"
|
|
140
|
+
? -(note.ticks + note.durationTicks - initialPosition)
|
|
141
|
+
: initialPosition - note.ticks);
|
|
107
142
|
setIsDragging(true);
|
|
108
143
|
setCurrentNoteIndex(noteIndex());
|
|
109
144
|
setCurrentNoteTrackIndex(trackIndex());
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const handleMouseMove = (mouseMoveEvent) => {
|
|
113
|
-
const note = currentNote();
|
|
114
|
-
if (!note)
|
|
115
|
-
return;
|
|
116
|
-
const ticks = snapValueToGridIfEnabled(Math.max(horizontalViewPort().calculatePosition(mouseMoveEvent.clientX) -
|
|
117
|
-
diffPosition, 0), mouseMoveEvent.altKey);
|
|
118
|
-
const updatedNote = {
|
|
119
|
-
...note,
|
|
120
|
-
...(noteDragMode() === "move" &&
|
|
121
|
-
context.mode === "keys" && {
|
|
122
|
-
midi: Math.round(127 -
|
|
123
|
-
verticalViewPort().calculatePosition(mouseMoveEvent.clientY)),
|
|
124
|
-
}),
|
|
125
|
-
...((noteDragMode() === "move" || noteDragMode() === "trimStart") && {
|
|
126
|
-
ticks,
|
|
127
|
-
}),
|
|
128
|
-
...(noteDragMode() === "trimStart" && {
|
|
129
|
-
durationTicks: note.durationTicks + note.ticks - ticks,
|
|
130
|
-
}),
|
|
131
|
-
...(noteDragMode() === "trimEnd" && {
|
|
132
|
-
durationTicks: snapValueToGridIfEnabled(horizontalViewPort().calculatePosition(mouseMoveEvent.clientX) -
|
|
133
|
-
note.ticks, mouseMoveEvent.altKey),
|
|
134
|
-
}),
|
|
135
|
-
};
|
|
136
|
-
const previousTrackIndex = currentNoteTrackIndex();
|
|
137
|
-
const previousNoteIndex = currentNoteIndex();
|
|
138
|
-
const targetTrackIndex = context.mode === "tracks"
|
|
139
|
-
? clamp(Math.floor(verticalViewPort().calculatePosition(mouseMoveEvent.clientY)), 0, context.tracks.length - 1)
|
|
140
|
-
: previousTrackIndex;
|
|
141
|
-
if (targetTrackIndex === previousTrackIndex) {
|
|
142
|
-
context.onNoteChange?.(previousTrackIndex, previousNoteIndex, updatedNote);
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
batch(() => {
|
|
146
|
-
if (context.onInsertNote) {
|
|
147
|
-
context.onRemoveNote?.(previousTrackIndex, previousNoteIndex);
|
|
148
|
-
const newNoteIndex = context.onInsertNote(targetTrackIndex, updatedNote);
|
|
149
|
-
setCurrentNoteTrackIndex(targetTrackIndex);
|
|
150
|
-
setCurrentNoteIndex(newNoteIndex);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
const handleMouseUp = () => {
|
|
156
|
-
setIsDragging(false);
|
|
157
|
-
setCurrentNoteIndex(-1);
|
|
158
|
-
setCurrentNoteTrackIndex(-1);
|
|
159
|
-
window.removeEventListener("mousemove", handleMouseMove);
|
|
160
|
-
window.removeEventListener("mouseup", handleMouseUp);
|
|
161
|
-
};
|
|
162
|
-
window.addEventListener("mousemove", handleMouseMove);
|
|
163
|
-
window.addEventListener("mouseup", handleMouseUp);
|
|
145
|
+
setInitialNote(note);
|
|
146
|
+
startDragging();
|
|
164
147
|
}} style={{
|
|
165
148
|
"background-color": `rgba(255,0,0, ${(128 + note.velocity) / 256})`,
|
|
166
149
|
top: `${verticalVirtualDimensions().offset}px`,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createEffect, createSignal } from "solid-js";
|
|
2
|
+
import { usePianoRollContext } from "./PianoRollContext";
|
|
3
|
+
import useBoundingClientRect from "./useBoundingClientRect";
|
|
4
|
+
import ScrollZoomContainer from "./viewport/ScrollZoomContainer";
|
|
5
|
+
const PianoRollNotesScroller = (props) => {
|
|
6
|
+
const context = usePianoRollContext();
|
|
7
|
+
const [ref, setRef] = createSignal();
|
|
8
|
+
const clientRect = useBoundingClientRect(ref);
|
|
9
|
+
createEffect(() => {
|
|
10
|
+
context.onNotesScrollerClientRectChange(clientRect());
|
|
11
|
+
});
|
|
12
|
+
return (<ScrollZoomContainer ref={setRef} verticalDimensionName={context.mode === "keys" ? "vertical" : "verticalTracks"}>
|
|
13
|
+
{props.children}
|
|
14
|
+
</ScrollZoomContainer>);
|
|
15
|
+
};
|
|
16
|
+
export default PianoRollNotesScroller;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createMemo, Index, Show } from "solid-js";
|
|
2
|
+
import { useViewPortDimension } from "./viewport/ScrollZoomViewPort";
|
|
3
|
+
import styles from "./PianoRollScale.module.css";
|
|
4
|
+
import usePianoRollGrid from "./usePianoRollGrid";
|
|
5
|
+
const PianoRollScale = () => {
|
|
6
|
+
const horizontalViewPort = createMemo(() => useViewPortDimension("horizontal"));
|
|
7
|
+
const grid = usePianoRollGrid();
|
|
8
|
+
return (<div class={styles.PianoRollScale}>
|
|
9
|
+
<Index each={grid()}>
|
|
10
|
+
{(entry) => {
|
|
11
|
+
return (<Show when={horizontalViewPort().isVisible(entry().virtualDimensions)}>
|
|
12
|
+
<div classList={{
|
|
13
|
+
[styles["PianoRollScale-Time"]]: true,
|
|
14
|
+
[styles["Highlighted"]]: entry().isHighlighted,
|
|
15
|
+
[styles["HighlightedBorder"]]: entry().hasHighlightedBorder,
|
|
16
|
+
}} style={{
|
|
17
|
+
left: `${entry().virtualDimensions.offset}px`,
|
|
18
|
+
width: `${entry().virtualDimensions.size}px`,
|
|
19
|
+
}}>
|
|
20
|
+
<Show when={entry().showLabel}>
|
|
21
|
+
<div class={styles["PianoRollScale-Label"]}>{entry().label}</div>
|
|
22
|
+
</Show>
|
|
23
|
+
</div>
|
|
24
|
+
</Show>);
|
|
25
|
+
}}
|
|
26
|
+
</Index>
|
|
27
|
+
</div>);
|
|
28
|
+
};
|
|
29
|
+
export default PianoRollScale;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { usePianoRollContext } from "./PianoRollContext";
|
|
2
|
+
import { ScrollZoomViewPort } from "./viewport/ScrollZoomViewPort";
|
|
3
|
+
const PianoRollScrollZoomViewPort = (props) => {
|
|
4
|
+
const zoomFactor = 500;
|
|
5
|
+
const context = usePianoRollContext();
|
|
6
|
+
return (<ScrollZoomViewPort dimensions={{
|
|
7
|
+
horizontal: () => ({
|
|
8
|
+
pixelOffset: context.notesScrollerClientRect.left,
|
|
9
|
+
pixelSize: context.notesScrollerClientRect.width,
|
|
10
|
+
position: context.position,
|
|
11
|
+
range: context.duration,
|
|
12
|
+
zoom: context.zoom * (zoomFactor / context.notesScrollerClientRect.width),
|
|
13
|
+
onPositionChange: context.onPositionChange,
|
|
14
|
+
onZoomChange: (zoom) => context.onZoomChange?.(zoom / (zoomFactor / context.notesScrollerClientRect.width)),
|
|
15
|
+
minZoom: 1,
|
|
16
|
+
maxZoom: 500,
|
|
17
|
+
}),
|
|
18
|
+
vertical: () => ({
|
|
19
|
+
pixelOffset: context.notesScrollerClientRect.top,
|
|
20
|
+
pixelSize: context.notesScrollerClientRect.height,
|
|
21
|
+
position: context.verticalPosition,
|
|
22
|
+
range: 128,
|
|
23
|
+
zoom: context.verticalZoom * (zoomFactor / context.notesScrollerClientRect.height),
|
|
24
|
+
onPositionChange: context.onVerticalPositionChange,
|
|
25
|
+
onZoomChange: (verticalZoom) => context.onVerticalZoomChange?.(verticalZoom / (zoomFactor / context.notesScrollerClientRect.height)),
|
|
26
|
+
minZoom: 1,
|
|
27
|
+
maxZoom: 10,
|
|
28
|
+
}),
|
|
29
|
+
horizontalTracks: () => ({
|
|
30
|
+
pixelOffset: 0,
|
|
31
|
+
pixelSize: context.tracksScrollerClientRect.width,
|
|
32
|
+
}),
|
|
33
|
+
verticalTracks: () => ({
|
|
34
|
+
pixelOffset: context.tracksScrollerClientRect.top,
|
|
35
|
+
pixelSize: context.tracksScrollerClientRect.height,
|
|
36
|
+
position: context.verticalTrackPosition,
|
|
37
|
+
range: context.tracks.length,
|
|
38
|
+
zoom: context.verticalTrackZoom * (zoomFactor / context.tracksScrollerClientRect.height),
|
|
39
|
+
onPositionChange: context.onVerticalTrackPositionChange,
|
|
40
|
+
onZoomChange: (verticalTrackZoom) => context.onVerticalTrackZoomChange?.(verticalTrackZoom / (zoomFactor / context.tracksScrollerClientRect.height)),
|
|
41
|
+
minZoom: 0.8,
|
|
42
|
+
maxZoom: 3,
|
|
43
|
+
}),
|
|
44
|
+
horizontalKeys: () => ({ pixelSize: 60 }),
|
|
45
|
+
}}>
|
|
46
|
+
{props.children}
|
|
47
|
+
</ScrollZoomViewPort>);
|
|
48
|
+
};
|
|
49
|
+
export default PianoRollScrollZoomViewPort;
|