solid-pianoroll 0.0.20 → 0.0.21
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 +74 -95
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +75 -96
- package/dist/esm/index.js.map +1 -1
- package/dist/source/PianoRollContext.jsx +2 -35
- package/dist/source/PianoRollKeys.jsx +4 -10
- package/dist/source/PlayHead.jsx +2 -5
- package/dist/source/usePianoRollState.js +44 -44
- package/dist/types/PianoRollContext.d.ts +63 -29
- package/dist/types/usePianoRollState.d.ts +18 -15
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createComponent, use, spread, mergeProps as mergeProps$1, insert, effect, template, delegateEvents, className, classList, setAttribute, memo } from 'solid-js/web';
|
|
2
|
-
import { createContext, splitProps, useContext, createEffect,
|
|
2
|
+
import { mergeProps, createContext, splitProps, useContext, createEffect, createMemo, createSignal, Index, Show, batch, For } from 'solid-js';
|
|
3
3
|
import { createStore } from 'solid-js/store';
|
|
4
4
|
|
|
5
5
|
function styleInject(css, ref) {
|
|
@@ -31,6 +31,73 @@ var css_248z$5 = ".PianoRoll-module_PianoRoll__rkRYx {\n box-sizing: border-box
|
|
|
31
31
|
var styles$5 = {"PianoRoll":"PianoRoll-module_PianoRoll__rkRYx","PianoRollContainer":"PianoRoll-module_PianoRollContainer__Oyxr7"};
|
|
32
32
|
styleInject(css_248z$5);
|
|
33
33
|
|
|
34
|
+
const defaultState = {
|
|
35
|
+
ppq: 0,
|
|
36
|
+
mode: "keys",
|
|
37
|
+
position: 0,
|
|
38
|
+
zoom: 10,
|
|
39
|
+
verticalZoom: 5,
|
|
40
|
+
verticalPosition: 44,
|
|
41
|
+
verticalTrackZoom: 0.5,
|
|
42
|
+
verticalTrackPosition: 0,
|
|
43
|
+
gridDivision: 4,
|
|
44
|
+
snapToGrid: true,
|
|
45
|
+
duration: 0,
|
|
46
|
+
tracks: [],
|
|
47
|
+
selectedTrackIndex: 0,
|
|
48
|
+
pressedKeys: []
|
|
49
|
+
};
|
|
50
|
+
const propNameToHandlerName = name => `on${name[0]?.toUpperCase()}${name.slice(1)}Change`;
|
|
51
|
+
const pianoRollStatePropNames = [...Object.keys(defaultState), ...Object.keys(defaultState).map(propNameToHandlerName), "onNoteChange", "onInsertNote", "onRemoveNote", "onNoteDown", "onNoteUp"];
|
|
52
|
+
const createPianoRollstate = initialState => {
|
|
53
|
+
const [state, setState] = createStore({
|
|
54
|
+
...defaultState,
|
|
55
|
+
...initialState
|
|
56
|
+
});
|
|
57
|
+
const handlers = Object.fromEntries(Object.entries(state).map(entry => {
|
|
58
|
+
return [propNameToHandlerName(entry[0]), value => setState(entry[0], value)];
|
|
59
|
+
}));
|
|
60
|
+
const updateNotes = async (trackIndex, getNotes) => {
|
|
61
|
+
const track = state.tracks[trackIndex];
|
|
62
|
+
if (!track) return;
|
|
63
|
+
const notes = track.notes;
|
|
64
|
+
handlers.onTracksChange([...state.tracks.slice(0, trackIndex), {
|
|
65
|
+
...track,
|
|
66
|
+
notes: getNotes(notes)
|
|
67
|
+
}, ...state.tracks.slice(trackIndex + 1)]);
|
|
68
|
+
};
|
|
69
|
+
const onNoteChange = (trackIndex, noteIndex, note) => {
|
|
70
|
+
updateNotes(trackIndex, notes => [...notes.slice(0, noteIndex), note, ...notes.slice(noteIndex + 1)]);
|
|
71
|
+
};
|
|
72
|
+
const onInsertNote = (trackIndex, note) => {
|
|
73
|
+
const track = state.tracks[trackIndex];
|
|
74
|
+
if (!track) return -1;
|
|
75
|
+
const notes = track.notes;
|
|
76
|
+
const newNoteIndex = Math.max(notes.findIndex(({
|
|
77
|
+
ticks
|
|
78
|
+
}) => ticks > note.ticks), 0);
|
|
79
|
+
updateNotes(trackIndex, notes => [...notes.slice(0, newNoteIndex), note, ...notes.slice(newNoteIndex)]);
|
|
80
|
+
return newNoteIndex;
|
|
81
|
+
};
|
|
82
|
+
const onRemoveNote = (trackIndex, noteIndex) => {
|
|
83
|
+
updateNotes(trackIndex, notes => [...notes.slice(0, noteIndex), ...notes.slice(noteIndex + 1)]);
|
|
84
|
+
};
|
|
85
|
+
const onNoteDown = keyNumber => {
|
|
86
|
+
handlers.onPressedKeysChange?.([...state.pressedKeys, keyNumber]);
|
|
87
|
+
};
|
|
88
|
+
const onNoteUp = keyNumber => {
|
|
89
|
+
handlers.onPressedKeysChange?.([...state.pressedKeys].filter(number => number !== keyNumber));
|
|
90
|
+
};
|
|
91
|
+
return mergeProps(state, {
|
|
92
|
+
...handlers,
|
|
93
|
+
onNoteChange,
|
|
94
|
+
onInsertNote,
|
|
95
|
+
onRemoveNote,
|
|
96
|
+
onNoteDown,
|
|
97
|
+
onNoteUp
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
34
101
|
const PianoRollContext = createContext();
|
|
35
102
|
const PianoRollContextProvider = PianoRollContext.Provider;
|
|
36
103
|
const usePianoRollContext = () => {
|
|
@@ -38,7 +105,7 @@ const usePianoRollContext = () => {
|
|
|
38
105
|
if (!context) throw new Error("No PianoRollContext found");
|
|
39
106
|
return context;
|
|
40
107
|
};
|
|
41
|
-
const splitContextProps = allProps => splitProps(allProps, [
|
|
108
|
+
const splitContextProps = allProps => splitProps(allProps, [...pianoRollStatePropNames, "showAllTracks", "showTrackList"]);
|
|
42
109
|
|
|
43
110
|
var css_248z$4 = ".PianoRollKeys-module_PianoRollKeys__5vnQ0 {\n position: relative;\n height: 100%;\n border-width: 0;\n border-color: #000;\n border-style: solid;\n border-right-width: 1px;\n border-left-width: 1px;\n background: white;\n cursor: pointer;\n}\n\n.PianoRollKeys-module_Key__jybNC {\n transition-property: background-color, box-shadow;\n transition-duration: 200ms;\n transition-timing-function: ease-out;\n border-width: 0px;\n position: absolute;\n box-sizing: border-box;\n width: 120%;\n left: -20%;\n border-color: #000;\n border-style: solid;\n}\n\n.PianoRollKeys-module_black__7rncB {\n background: black;\n border-top-right-radius: 12%;\n border-bottom-right-radius: 12%;\n margin-left: -20%;\n z-index: 1;\n}\n\n.PianoRollKeys-module_white__fR2Lm {\n background: white;\n border-top-width: 0.5px;\n border-bottom-width: 0.5px;\n}\n\n.PianoRollKeys-module_down__GcNeZ {\n transition: none;\n background: red;\n}\n";
|
|
44
111
|
var styles$4 = {"PianoRollKeys":"PianoRollKeys-module_PianoRollKeys__5vnQ0","Key":"PianoRollKeys-module_Key__jybNC","black":"PianoRollKeys-module_black__7rncB","white":"PianoRollKeys-module_white__fR2Lm","down":"PianoRollKeys-module_down__GcNeZ"};
|
|
@@ -284,12 +351,6 @@ const PianoRollKeys = () => {
|
|
|
284
351
|
each: keys,
|
|
285
352
|
children: key => {
|
|
286
353
|
const isDown = createMemo(() => context.pressedKeys.includes(key().number));
|
|
287
|
-
const handleKeyDown = () => {
|
|
288
|
-
context.onPressedKeysChange?.([...context.pressedKeys, key().number]);
|
|
289
|
-
};
|
|
290
|
-
const handleKeyUp = () => {
|
|
291
|
-
context.onPressedKeysChange?.([...context.pressedKeys].filter(number => number !== key().number));
|
|
292
|
-
};
|
|
293
354
|
const virtualDimensions = createMemo(() => verticalViewPort().calculatePixelDimensions(127 - key().number, 1));
|
|
294
355
|
const previousIsBlack = blackKeys.includes((key().number - 1) % 12);
|
|
295
356
|
const nextIsBlack = blackKeys.includes((key().number + 1) % 12);
|
|
@@ -301,20 +362,20 @@ const PianoRollKeys = () => {
|
|
|
301
362
|
const _el$2 = _tmpl$$6.cloneNode(true);
|
|
302
363
|
_el$2.addEventListener("mouseleave", () => {
|
|
303
364
|
if (isMouseDown()) {
|
|
304
|
-
|
|
365
|
+
context.onNoteUp(key().number);
|
|
305
366
|
}
|
|
306
367
|
});
|
|
307
368
|
_el$2.addEventListener("mouseenter", () => {
|
|
308
369
|
if (isMouseDown()) {
|
|
309
|
-
|
|
370
|
+
context.onNoteDown(key().number);
|
|
310
371
|
}
|
|
311
372
|
});
|
|
312
373
|
_el$2.$$mouseup = () => {
|
|
313
|
-
|
|
374
|
+
context.onNoteUp(key().number);
|
|
314
375
|
};
|
|
315
376
|
_el$2.$$mousedown = () => {
|
|
316
377
|
setIsMouseDown(true);
|
|
317
|
-
|
|
378
|
+
context.onNoteDown(key().number);
|
|
318
379
|
};
|
|
319
380
|
insert(_el$2, createComponent(Show, {
|
|
320
381
|
get when() {
|
|
@@ -1066,13 +1127,9 @@ const PlayHead = allProps => {
|
|
|
1066
1127
|
event.preventDefault();
|
|
1067
1128
|
event.stopPropagation();
|
|
1068
1129
|
const handleMouseMove = ({
|
|
1069
|
-
|
|
1130
|
+
clientX
|
|
1070
1131
|
}) => {
|
|
1071
|
-
const
|
|
1072
|
-
parentElement
|
|
1073
|
-
} = event.currentTarget;
|
|
1074
|
-
if (!parentElement) return;
|
|
1075
|
-
const newPosition = viewPort.calculatePosition(leftPosition() + movementX);
|
|
1132
|
+
const newPosition = viewPort.calculatePosition(clientX);
|
|
1076
1133
|
props.onPlayHeadPositionChange?.(newPosition);
|
|
1077
1134
|
};
|
|
1078
1135
|
const handleMouseUp = () => {
|
|
@@ -1111,83 +1168,5 @@ const useNotes = () => {
|
|
|
1111
1168
|
};
|
|
1112
1169
|
};
|
|
1113
1170
|
|
|
1114
|
-
const createPianoRollstate = defaultState => {
|
|
1115
|
-
const [state, setState] = createStore({
|
|
1116
|
-
ppq: 0,
|
|
1117
|
-
mode: "keys",
|
|
1118
|
-
position: 0,
|
|
1119
|
-
zoom: 10,
|
|
1120
|
-
verticalZoom: 5,
|
|
1121
|
-
verticalPosition: 44,
|
|
1122
|
-
verticalTrackZoom: 0.5,
|
|
1123
|
-
verticalTrackPosition: 0,
|
|
1124
|
-
gridDivision: 4,
|
|
1125
|
-
snapToGrid: true,
|
|
1126
|
-
duration: 0,
|
|
1127
|
-
tracks: [],
|
|
1128
|
-
selectedTrackIndex: 0,
|
|
1129
|
-
pressedKeys: [],
|
|
1130
|
-
...defaultState
|
|
1131
|
-
});
|
|
1132
|
-
const updateNotes = async (trackIndex, getNotes) => {
|
|
1133
|
-
const track = state.tracks[trackIndex];
|
|
1134
|
-
if (!track) return;
|
|
1135
|
-
const notes = track.notes;
|
|
1136
|
-
onTracksChange([...state.tracks.slice(0, trackIndex), {
|
|
1137
|
-
...track,
|
|
1138
|
-
notes: getNotes(notes)
|
|
1139
|
-
}, ...state.tracks.slice(trackIndex + 1)]);
|
|
1140
|
-
};
|
|
1141
|
-
const onNoteChange = (trackIndex, noteIndex, note) => {
|
|
1142
|
-
updateNotes(trackIndex, notes => [...notes.slice(0, noteIndex), note, ...notes.slice(noteIndex + 1)]);
|
|
1143
|
-
};
|
|
1144
|
-
const onInsertNote = (trackIndex, note) => {
|
|
1145
|
-
const track = state.tracks[trackIndex];
|
|
1146
|
-
if (!track) return -1;
|
|
1147
|
-
const notes = track.notes;
|
|
1148
|
-
const newNoteIndex = Math.max(notes.findIndex(({
|
|
1149
|
-
ticks
|
|
1150
|
-
}) => ticks > note.ticks), 0);
|
|
1151
|
-
updateNotes(trackIndex, notes => [...notes.slice(0, newNoteIndex), note, ...notes.slice(newNoteIndex)]);
|
|
1152
|
-
return newNoteIndex;
|
|
1153
|
-
};
|
|
1154
|
-
const onRemoveNote = (trackIndex, noteIndex) => {
|
|
1155
|
-
updateNotes(trackIndex, notes => [...notes.slice(0, noteIndex), ...notes.slice(noteIndex + 1)]);
|
|
1156
|
-
};
|
|
1157
|
-
const onPpqChange = ppq => setState("ppq", ppq);
|
|
1158
|
-
const onModeChange = mode => setState("mode", mode);
|
|
1159
|
-
const onPositionChange = position => setState("position", position);
|
|
1160
|
-
const onZoomChange = zoom => setState("zoom", zoom);
|
|
1161
|
-
const onVerticalZoomChange = verticalZoom => setState("verticalZoom", verticalZoom);
|
|
1162
|
-
const onVerticalPositionChange = verticalPosition => setState("verticalPosition", verticalPosition);
|
|
1163
|
-
const onVerticalTrackZoomChange = verticalTrackZoom => setState("verticalTrackZoom", verticalTrackZoom);
|
|
1164
|
-
const onVerticalTrackPositionChange = verticalTrackPosition => setState("verticalTrackPosition", verticalTrackPosition);
|
|
1165
|
-
const onGridDivisionChange = gridDivision => setState("gridDivision", gridDivision);
|
|
1166
|
-
const onSnapToGridChange = snapToGrid => setState("snapToGrid", snapToGrid);
|
|
1167
|
-
const onDurationChange = duration => setState("duration", duration);
|
|
1168
|
-
const onTracksChange = tracks => setState("tracks", tracks);
|
|
1169
|
-
const onSelectedTrackIndexChange = selectedTrackIndex => setState("selectedTrackIndex", selectedTrackIndex);
|
|
1170
|
-
const onPressedKeysChange = pressedKeys => setState("pressedKeys", pressedKeys);
|
|
1171
|
-
return mergeProps(state, {
|
|
1172
|
-
onPpqChange,
|
|
1173
|
-
onModeChange,
|
|
1174
|
-
onPositionChange,
|
|
1175
|
-
onZoomChange,
|
|
1176
|
-
onVerticalZoomChange,
|
|
1177
|
-
onVerticalPositionChange,
|
|
1178
|
-
onVerticalTrackZoomChange,
|
|
1179
|
-
onVerticalTrackPositionChange,
|
|
1180
|
-
onGridDivisionChange,
|
|
1181
|
-
onSnapToGridChange,
|
|
1182
|
-
onDurationChange,
|
|
1183
|
-
onTracksChange,
|
|
1184
|
-
onNoteChange,
|
|
1185
|
-
onInsertNote,
|
|
1186
|
-
onRemoveNote,
|
|
1187
|
-
onSelectedTrackIndexChange,
|
|
1188
|
-
onPressedKeysChange
|
|
1189
|
-
});
|
|
1190
|
-
};
|
|
1191
|
-
|
|
1192
1171
|
export { PianoRoll, PlayHead, createPianoRollstate, useNotes };
|
|
1193
1172
|
//# sourceMappingURL=index.js.map
|