solid-pianoroll 0.0.13 → 0.0.15

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.
@@ -1,136 +0,0 @@
1
- import { createSignal, mergeProps, createMemo, Index, createEffect, splitProps, Show, } from "solid-js";
2
- import styles from "./PianoRoll.module.css";
3
- import HorizontalZoomControl from "./viewport/HorizontalZoomControl";
4
- import { PianoRollContextProvider, splitContextProps } from "./PianoRollContext";
5
- import PianoRollNotes from "./PianoRollNotes";
6
- import ScrollContainer from "./viewport/ScrollContainer";
7
- import PianoRollGrid from "./PianoRollGrid";
8
- import useNotes from "./useNotes";
9
- import useBoundingClientRect from "./useBoundingClientRect";
10
- import { ScrollZoomViewPort, useViewPortDimension } from "./viewport/ScrollZoomViewPort";
11
- import { clamp } from "./viewport/createViewPortDimension";
12
- import { createStore } from "solid-js/store";
13
- import PianoRollKeys from "./PianoRollKeys";
14
- import VerticalZoomControl from "./viewport/VerticalZoomControl";
15
- const MultiTrackPianoRoll = (allProps) => {
16
- const condensed = createMemo(() => !allProps.selectedTrack);
17
- const [ownProps, restProps] = splitProps(allProps, ["tracks", "selectedTrack"]);
18
- const [contextProps, divProps] = splitContextProps(mergeProps(restProps, { notes: [], condensed: false }));
19
- const [scrollerRef, setScrollerRef] = createSignal();
20
- const clientRect = useBoundingClientRect(scrollerRef);
21
- const zoomFactor = 500;
22
- const minZoom = createMemo(() => 1 / (zoomFactor / clientRect().width));
23
- const maxZoom = createMemo(() => 500 * (zoomFactor / clientRect().width));
24
- const minVerticalZoom = createMemo(() => 1 / (zoomFactor / clientRect().height));
25
- const maxVerticalZoom = createMemo(() => 10 * (zoomFactor / clientRect().height));
26
- return (<PianoRollContextProvider value={{ ...contextProps }}>
27
- <ScrollZoomViewPort dimensions={{
28
- horizontal: () => ({
29
- pixelOffset: clientRect().left,
30
- pixelSize: clientRect().width,
31
- position: contextProps.position,
32
- range: contextProps.duration,
33
- zoom: contextProps.zoom * (zoomFactor / clientRect().width),
34
- onPositionChange: contextProps.onPositionChange,
35
- onZoomChange: (zoom) => contextProps.onZoomChange?.(clamp(zoom / (zoomFactor / clientRect().width), minZoom(), maxZoom())),
36
- }),
37
- vertical: () => ({
38
- pixelOffset: clientRect().top,
39
- pixelSize: clientRect().height,
40
- position: contextProps.verticalPosition,
41
- range: 128,
42
- zoom: contextProps.verticalZoom * (zoomFactor / clientRect().height),
43
- onPositionChange: contextProps.onVerticalPositionChange,
44
- onZoomChange: (verticalZoom) => contextProps.onVerticalZoomChange?.(clamp(verticalZoom / (zoomFactor / clientRect().height), minVerticalZoom(), maxVerticalZoom())),
45
- }),
46
- }}>
47
- <div style={{
48
- display: "flex",
49
- flex: 1,
50
- height: "100%",
51
- "flex-direction": "row",
52
- }}>
53
- <ul style={{ "margin-block-start": 0, "padding-inline-start": 0, width: "150px" }}>
54
- <Index each={allProps.tracks}>
55
- {(track) => (<li style={{
56
- width: "150px",
57
- height: "30px",
58
- "list-style": "none",
59
- display: "flex",
60
- "align-items": "center",
61
- "border-top": "1px black solid",
62
- background: track() === allProps.selectedTrack ? "lightgray" : "none",
63
- cursor: "pointer",
64
- }} onClick={() => {
65
- if (track() === allProps.selectedTrack) {
66
- allProps.onSelectedTrackChange(undefined);
67
- }
68
- else {
69
- allProps.onSelectedTrackChange(track());
70
- }
71
- }}>
72
- {track().name}
73
- </li>)}
74
- </Index>
75
- </ul>
76
-
77
- <div class={styles.PianoRoll} style={{ flex: 1 }}>
78
- <div class={styles.PianoRollContainer}>
79
- <Show when={!condensed()}>
80
- <PianoRollKeys />
81
- </Show>
82
-
83
- <ScrollContainer ref={setScrollerRef}>
84
- <ul style={{
85
- margin: 0,
86
- "margin-block-start": 0,
87
- "padding-inline-start": 0,
88
- }}>
89
- <Index each={allProps.tracks}>
90
- {(track) => {
91
- const notes = useNotes();
92
- createEffect(() => {
93
- notes.onNotesChange(track().notes);
94
- });
95
- const [context, setContext] = createStore({ ...contextProps });
96
- createEffect(() => {
97
- setContext({
98
- ...contextProps,
99
- condensed: condensed(),
100
- notes: notes.notes(),
101
- onNoteChange: notes.onNoteChange,
102
- onInsertNote: notes.onInsertNote,
103
- onRemoveNote: notes.onRemoveNote,
104
- });
105
- });
106
- const verticalViewPort = useViewPortDimension("vertical");
107
- return (<Show when={condensed() || allProps.selectedTrack === track()}>
108
- <PianoRollContextProvider value={context}>
109
- <li style={{
110
- display: "flex",
111
- position: "relative",
112
- "list-style": "none",
113
- "flex-direction": "row",
114
- height: condensed() ? "30px" : `${verticalViewPort.pixelSize}px`,
115
- "border-top": "1px black solid",
116
- }}>
117
- <PianoRollNotes />
118
- <PianoRollGrid />
119
- </li>
120
- </PianoRollContextProvider>
121
- </Show>);
122
- }}
123
- </Index>
124
- </ul>
125
- </ScrollContainer>
126
- <Show when={!condensed()}>
127
- <VerticalZoomControl value={contextProps.verticalZoom} onInput={(event) => contextProps.onVerticalZoomChange?.(event.currentTarget.valueAsNumber)}/>
128
- </Show>
129
- </div>
130
- <HorizontalZoomControl style={{ width: "100%", "margin-left": 0 }} value={contextProps.zoom} onInput={(event) => contextProps.onZoomChange?.(event.currentTarget.valueAsNumber)}/>
131
- </div>
132
- </div>
133
- </ScrollZoomViewPort>
134
- </PianoRollContextProvider>);
135
- };
136
- export default MultiTrackPianoRoll;
@@ -1,10 +0,0 @@
1
- import { JSX } from "solid-js";
2
- import { TrackJSON } from "@tonejs/midi";
3
- import { PianoRollProps } from "./PianoRoll";
4
- export type MultiTrackPianoRollProps = Omit<PianoRollProps, "notes" | "onNoteChange" | "onInsertNote" | "onRemoveNote" | "condensed"> & {
5
- tracks: TrackJSON[];
6
- selectedTrack?: TrackJSON;
7
- onSelectedTrackChange: (track?: TrackJSON) => void;
8
- } & JSX.IntrinsicElements["div"];
9
- declare const MultiTrackPianoRoll: (allProps: MultiTrackPianoRollProps) => JSX.Element;
10
- export default MultiTrackPianoRoll;