solid-pianoroll 0.0.19 → 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 +75 -96
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.js +76 -97
- package/dist/esm/index.js.map +1 -1
- package/dist/source/PianoRoll.jsx +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/cjs/index.js
CHANGED
|
@@ -33,6 +33,73 @@ var css_248z$5 = ".PianoRoll-module_PianoRoll__rkRYx {\n box-sizing: border-box
|
|
|
33
33
|
var styles$5 = {"PianoRoll":"PianoRoll-module_PianoRoll__rkRYx","PianoRollContainer":"PianoRoll-module_PianoRollContainer__Oyxr7"};
|
|
34
34
|
styleInject(css_248z$5);
|
|
35
35
|
|
|
36
|
+
const defaultState = {
|
|
37
|
+
ppq: 0,
|
|
38
|
+
mode: "keys",
|
|
39
|
+
position: 0,
|
|
40
|
+
zoom: 10,
|
|
41
|
+
verticalZoom: 5,
|
|
42
|
+
verticalPosition: 44,
|
|
43
|
+
verticalTrackZoom: 0.5,
|
|
44
|
+
verticalTrackPosition: 0,
|
|
45
|
+
gridDivision: 4,
|
|
46
|
+
snapToGrid: true,
|
|
47
|
+
duration: 0,
|
|
48
|
+
tracks: [],
|
|
49
|
+
selectedTrackIndex: 0,
|
|
50
|
+
pressedKeys: []
|
|
51
|
+
};
|
|
52
|
+
const propNameToHandlerName = name => `on${name[0]?.toUpperCase()}${name.slice(1)}Change`;
|
|
53
|
+
const pianoRollStatePropNames = [...Object.keys(defaultState), ...Object.keys(defaultState).map(propNameToHandlerName), "onNoteChange", "onInsertNote", "onRemoveNote", "onNoteDown", "onNoteUp"];
|
|
54
|
+
const createPianoRollstate = initialState => {
|
|
55
|
+
const [state, setState] = store.createStore({
|
|
56
|
+
...defaultState,
|
|
57
|
+
...initialState
|
|
58
|
+
});
|
|
59
|
+
const handlers = Object.fromEntries(Object.entries(state).map(entry => {
|
|
60
|
+
return [propNameToHandlerName(entry[0]), value => setState(entry[0], value)];
|
|
61
|
+
}));
|
|
62
|
+
const updateNotes = async (trackIndex, getNotes) => {
|
|
63
|
+
const track = state.tracks[trackIndex];
|
|
64
|
+
if (!track) return;
|
|
65
|
+
const notes = track.notes;
|
|
66
|
+
handlers.onTracksChange([...state.tracks.slice(0, trackIndex), {
|
|
67
|
+
...track,
|
|
68
|
+
notes: getNotes(notes)
|
|
69
|
+
}, ...state.tracks.slice(trackIndex + 1)]);
|
|
70
|
+
};
|
|
71
|
+
const onNoteChange = (trackIndex, noteIndex, note) => {
|
|
72
|
+
updateNotes(trackIndex, notes => [...notes.slice(0, noteIndex), note, ...notes.slice(noteIndex + 1)]);
|
|
73
|
+
};
|
|
74
|
+
const onInsertNote = (trackIndex, note) => {
|
|
75
|
+
const track = state.tracks[trackIndex];
|
|
76
|
+
if (!track) return -1;
|
|
77
|
+
const notes = track.notes;
|
|
78
|
+
const newNoteIndex = Math.max(notes.findIndex(({
|
|
79
|
+
ticks
|
|
80
|
+
}) => ticks > note.ticks), 0);
|
|
81
|
+
updateNotes(trackIndex, notes => [...notes.slice(0, newNoteIndex), note, ...notes.slice(newNoteIndex)]);
|
|
82
|
+
return newNoteIndex;
|
|
83
|
+
};
|
|
84
|
+
const onRemoveNote = (trackIndex, noteIndex) => {
|
|
85
|
+
updateNotes(trackIndex, notes => [...notes.slice(0, noteIndex), ...notes.slice(noteIndex + 1)]);
|
|
86
|
+
};
|
|
87
|
+
const onNoteDown = keyNumber => {
|
|
88
|
+
handlers.onPressedKeysChange?.([...state.pressedKeys, keyNumber]);
|
|
89
|
+
};
|
|
90
|
+
const onNoteUp = keyNumber => {
|
|
91
|
+
handlers.onPressedKeysChange?.([...state.pressedKeys].filter(number => number !== keyNumber));
|
|
92
|
+
};
|
|
93
|
+
return solidJs.mergeProps(state, {
|
|
94
|
+
...handlers,
|
|
95
|
+
onNoteChange,
|
|
96
|
+
onInsertNote,
|
|
97
|
+
onRemoveNote,
|
|
98
|
+
onNoteDown,
|
|
99
|
+
onNoteUp
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
|
|
36
103
|
const PianoRollContext = solidJs.createContext();
|
|
37
104
|
const PianoRollContextProvider = PianoRollContext.Provider;
|
|
38
105
|
const usePianoRollContext = () => {
|
|
@@ -40,7 +107,7 @@ const usePianoRollContext = () => {
|
|
|
40
107
|
if (!context) throw new Error("No PianoRollContext found");
|
|
41
108
|
return context;
|
|
42
109
|
};
|
|
43
|
-
const splitContextProps = allProps => solidJs.splitProps(allProps, [
|
|
110
|
+
const splitContextProps = allProps => solidJs.splitProps(allProps, [...pianoRollStatePropNames, "showAllTracks", "showTrackList"]);
|
|
44
111
|
|
|
45
112
|
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";
|
|
46
113
|
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"};
|
|
@@ -286,12 +353,6 @@ const PianoRollKeys = () => {
|
|
|
286
353
|
each: keys,
|
|
287
354
|
children: key => {
|
|
288
355
|
const isDown = solidJs.createMemo(() => context.pressedKeys.includes(key().number));
|
|
289
|
-
const handleKeyDown = () => {
|
|
290
|
-
context.onPressedKeysChange?.([...context.pressedKeys, key().number]);
|
|
291
|
-
};
|
|
292
|
-
const handleKeyUp = () => {
|
|
293
|
-
context.onPressedKeysChange?.([...context.pressedKeys].filter(number => number !== key().number));
|
|
294
|
-
};
|
|
295
356
|
const virtualDimensions = solidJs.createMemo(() => verticalViewPort().calculatePixelDimensions(127 - key().number, 1));
|
|
296
357
|
const previousIsBlack = blackKeys.includes((key().number - 1) % 12);
|
|
297
358
|
const nextIsBlack = blackKeys.includes((key().number + 1) % 12);
|
|
@@ -303,20 +364,20 @@ const PianoRollKeys = () => {
|
|
|
303
364
|
const _el$2 = _tmpl$$6.cloneNode(true);
|
|
304
365
|
_el$2.addEventListener("mouseleave", () => {
|
|
305
366
|
if (isMouseDown()) {
|
|
306
|
-
|
|
367
|
+
context.onNoteUp(key().number);
|
|
307
368
|
}
|
|
308
369
|
});
|
|
309
370
|
_el$2.addEventListener("mouseenter", () => {
|
|
310
371
|
if (isMouseDown()) {
|
|
311
|
-
|
|
372
|
+
context.onNoteDown(key().number);
|
|
312
373
|
}
|
|
313
374
|
});
|
|
314
375
|
_el$2.$$mouseup = () => {
|
|
315
|
-
|
|
376
|
+
context.onNoteUp(key().number);
|
|
316
377
|
};
|
|
317
378
|
_el$2.$$mousedown = () => {
|
|
318
379
|
setIsMouseDown(true);
|
|
319
|
-
|
|
380
|
+
context.onNoteDown(key().number);
|
|
320
381
|
};
|
|
321
382
|
web.insert(_el$2, web.createComponent(solidJs.Show, {
|
|
322
383
|
get when() {
|
|
@@ -948,7 +1009,7 @@ const PianoRoll = allProps => {
|
|
|
948
1009
|
}),
|
|
949
1010
|
horizontalTracks: () => ({
|
|
950
1011
|
pixelOffset: 0,
|
|
951
|
-
pixelSize:
|
|
1012
|
+
pixelSize: tracksScrollerClientRect().width
|
|
952
1013
|
}),
|
|
953
1014
|
verticalTracks: () => ({
|
|
954
1015
|
pixelOffset: tracksScrollerClientRect().top,
|
|
@@ -1068,13 +1129,9 @@ const PlayHead = allProps => {
|
|
|
1068
1129
|
event.preventDefault();
|
|
1069
1130
|
event.stopPropagation();
|
|
1070
1131
|
const handleMouseMove = ({
|
|
1071
|
-
|
|
1132
|
+
clientX
|
|
1072
1133
|
}) => {
|
|
1073
|
-
const
|
|
1074
|
-
parentElement
|
|
1075
|
-
} = event.currentTarget;
|
|
1076
|
-
if (!parentElement) return;
|
|
1077
|
-
const newPosition = viewPort.calculatePosition(leftPosition() + movementX);
|
|
1134
|
+
const newPosition = viewPort.calculatePosition(clientX);
|
|
1078
1135
|
props.onPlayHeadPositionChange?.(newPosition);
|
|
1079
1136
|
};
|
|
1080
1137
|
const handleMouseUp = () => {
|
|
@@ -1113,84 +1170,6 @@ const useNotes = () => {
|
|
|
1113
1170
|
};
|
|
1114
1171
|
};
|
|
1115
1172
|
|
|
1116
|
-
const createPianoRollstate = defaultState => {
|
|
1117
|
-
const [state, setState] = store.createStore({
|
|
1118
|
-
ppq: 0,
|
|
1119
|
-
mode: "keys",
|
|
1120
|
-
position: 0,
|
|
1121
|
-
zoom: 10,
|
|
1122
|
-
verticalZoom: 5,
|
|
1123
|
-
verticalPosition: 44,
|
|
1124
|
-
verticalTrackZoom: 0.5,
|
|
1125
|
-
verticalTrackPosition: 0,
|
|
1126
|
-
gridDivision: 4,
|
|
1127
|
-
snapToGrid: true,
|
|
1128
|
-
duration: 0,
|
|
1129
|
-
tracks: [],
|
|
1130
|
-
selectedTrackIndex: 0,
|
|
1131
|
-
pressedKeys: [],
|
|
1132
|
-
...defaultState
|
|
1133
|
-
});
|
|
1134
|
-
const updateNotes = async (trackIndex, getNotes) => {
|
|
1135
|
-
const track = state.tracks[trackIndex];
|
|
1136
|
-
if (!track) return;
|
|
1137
|
-
const notes = track.notes;
|
|
1138
|
-
onTracksChange([...state.tracks.slice(0, trackIndex), {
|
|
1139
|
-
...track,
|
|
1140
|
-
notes: getNotes(notes)
|
|
1141
|
-
}, ...state.tracks.slice(trackIndex + 1)]);
|
|
1142
|
-
};
|
|
1143
|
-
const onNoteChange = (trackIndex, noteIndex, note) => {
|
|
1144
|
-
updateNotes(trackIndex, notes => [...notes.slice(0, noteIndex), note, ...notes.slice(noteIndex + 1)]);
|
|
1145
|
-
};
|
|
1146
|
-
const onInsertNote = (trackIndex, note) => {
|
|
1147
|
-
const track = state.tracks[trackIndex];
|
|
1148
|
-
if (!track) return -1;
|
|
1149
|
-
const notes = track.notes;
|
|
1150
|
-
const newNoteIndex = Math.max(notes.findIndex(({
|
|
1151
|
-
ticks
|
|
1152
|
-
}) => ticks > note.ticks), 0);
|
|
1153
|
-
updateNotes(trackIndex, notes => [...notes.slice(0, newNoteIndex), note, ...notes.slice(newNoteIndex)]);
|
|
1154
|
-
return newNoteIndex;
|
|
1155
|
-
};
|
|
1156
|
-
const onRemoveNote = (trackIndex, noteIndex) => {
|
|
1157
|
-
updateNotes(trackIndex, notes => [...notes.slice(0, noteIndex), ...notes.slice(noteIndex + 1)]);
|
|
1158
|
-
};
|
|
1159
|
-
const onPpqChange = ppq => setState("ppq", ppq);
|
|
1160
|
-
const onModeChange = mode => setState("mode", mode);
|
|
1161
|
-
const onPositionChange = position => setState("position", position);
|
|
1162
|
-
const onZoomChange = zoom => setState("zoom", zoom);
|
|
1163
|
-
const onVerticalZoomChange = verticalZoom => setState("verticalZoom", verticalZoom);
|
|
1164
|
-
const onVerticalPositionChange = verticalPosition => setState("verticalPosition", verticalPosition);
|
|
1165
|
-
const onVerticalTrackZoomChange = verticalTrackZoom => setState("verticalTrackZoom", verticalTrackZoom);
|
|
1166
|
-
const onVerticalTrackPositionChange = verticalTrackPosition => setState("verticalTrackPosition", verticalTrackPosition);
|
|
1167
|
-
const onGridDivisionChange = gridDivision => setState("gridDivision", gridDivision);
|
|
1168
|
-
const onSnapToGridChange = snapToGrid => setState("snapToGrid", snapToGrid);
|
|
1169
|
-
const onDurationChange = duration => setState("duration", duration);
|
|
1170
|
-
const onTracksChange = tracks => setState("tracks", tracks);
|
|
1171
|
-
const onSelectedTrackIndexChange = selectedTrackIndex => setState("selectedTrackIndex", selectedTrackIndex);
|
|
1172
|
-
const onPressedKeysChange = pressedKeys => setState("pressedKeys", pressedKeys);
|
|
1173
|
-
return solidJs.mergeProps(state, {
|
|
1174
|
-
onPpqChange,
|
|
1175
|
-
onModeChange,
|
|
1176
|
-
onPositionChange,
|
|
1177
|
-
onZoomChange,
|
|
1178
|
-
onVerticalZoomChange,
|
|
1179
|
-
onVerticalPositionChange,
|
|
1180
|
-
onVerticalTrackZoomChange,
|
|
1181
|
-
onVerticalTrackPositionChange,
|
|
1182
|
-
onGridDivisionChange,
|
|
1183
|
-
onSnapToGridChange,
|
|
1184
|
-
onDurationChange,
|
|
1185
|
-
onTracksChange,
|
|
1186
|
-
onNoteChange,
|
|
1187
|
-
onInsertNote,
|
|
1188
|
-
onRemoveNote,
|
|
1189
|
-
onSelectedTrackIndexChange,
|
|
1190
|
-
onPressedKeysChange
|
|
1191
|
-
});
|
|
1192
|
-
};
|
|
1193
|
-
|
|
1194
1173
|
exports.PianoRoll = PianoRoll;
|
|
1195
1174
|
exports.PlayHead = PlayHead;
|
|
1196
1175
|
exports.createPianoRollstate = createPianoRollstate;
|