solid-pianoroll 0.0.21 → 0.0.22

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 CHANGED
@@ -29,8 +29,8 @@ function styleInject(css, ref) {
29
29
  }
30
30
  }
31
31
 
32
- var css_248z$5 = ".PianoRoll-module_PianoRoll__rkRYx {\n box-sizing: border-box;\n display: flex;\n overflow: hidden;\n flex-direction: column;\n height: 100%;\n}\n\n.PianoRoll-module_PianoRollContainer__Oyxr7 {\n overflow: hidden;\n height: 100%;\n display: flex;\n flex-direction: row;\n}\n";
33
- var styles$5 = {"PianoRoll":"PianoRoll-module_PianoRoll__rkRYx","PianoRollContainer":"PianoRoll-module_PianoRollContainer__Oyxr7"};
32
+ var css_248z$5 = ".PianoRoll-module_PianoRoll__rkRYx {\n box-sizing: border-box;\n display: flex;\n overflow: hidden;\n flex-direction: column;\n height: 100%;\n}\n\n.PianoRoll-module_PianoRollContainer__Oyxr7 {\n overflow: hidden;\n height: 100%;\n display: flex;\n flex-direction: row;\n}\n\n.PianoRoll-module_PianoRollLeftColumn__S6SZQ {\n display: flex;\n width: 30%;\n max-width: 250px;\n}\n";
33
+ var styles$5 = {"PianoRoll":"PianoRoll-module_PianoRoll__rkRYx","PianoRollContainer":"PianoRoll-module_PianoRollContainer__Oyxr7","PianoRollLeftColumn":"PianoRoll-module_PianoRollLeftColumn__S6SZQ"};
34
34
  styleInject(css_248z$5);
35
35
 
36
36
  const defaultState = {
@@ -47,10 +47,10 @@ const defaultState = {
47
47
  duration: 0,
48
48
  tracks: [],
49
49
  selectedTrackIndex: 0,
50
- pressedKeys: []
50
+ pressedKeys: {}
51
51
  };
52
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"];
53
+ const pianoRollStatePropNames = [...Object.keys(defaultState), ...Object.keys(defaultState).map(propNameToHandlerName), "onNoteChange", "onInsertNote", "onRemoveNote", "onNoteDown", "onNoteUp", "isKeyDown"];
54
54
  const createPianoRollstate = initialState => {
55
55
  const [state, setState] = store.createStore({
56
56
  ...defaultState,
@@ -84,19 +84,30 @@ const createPianoRollstate = initialState => {
84
84
  const onRemoveNote = (trackIndex, noteIndex) => {
85
85
  updateNotes(trackIndex, notes => [...notes.slice(0, noteIndex), ...notes.slice(noteIndex + 1)]);
86
86
  };
87
- const onNoteDown = keyNumber => {
88
- handlers.onPressedKeysChange?.([...state.pressedKeys, keyNumber]);
87
+ const updateKeyPressedState = (trackIndex, keyNumber, value) => {
88
+ handlers.onPressedKeysChange?.({
89
+ ...state.pressedKeys,
90
+ [trackIndex]: {
91
+ ...state.pressedKeys[trackIndex],
92
+ [keyNumber]: value
93
+ }
94
+ });
89
95
  };
90
- const onNoteUp = keyNumber => {
91
- handlers.onPressedKeysChange?.([...state.pressedKeys].filter(number => number !== keyNumber));
96
+ const onNoteDown = (trackIndex, keyNumber) => {
97
+ updateKeyPressedState(trackIndex, keyNumber, true);
92
98
  };
99
+ const onNoteUp = (trackIndex, keyNumber) => {
100
+ updateKeyPressedState(trackIndex, keyNumber, false);
101
+ };
102
+ const isKeyDown = (trackIndex, keyNumber) => !!state.pressedKeys[trackIndex]?.[keyNumber];
93
103
  return solidJs.mergeProps(state, {
94
104
  ...handlers,
95
105
  onNoteChange,
96
106
  onInsertNote,
97
107
  onRemoveNote,
98
108
  onNoteDown,
99
- onNoteUp
109
+ onNoteUp,
110
+ isKeyDown
100
111
  });
101
112
  };
102
113
 
@@ -109,7 +120,7 @@ const usePianoRollContext = () => {
109
120
  };
110
121
  const splitContextProps = allProps => solidJs.splitProps(allProps, [...pianoRollStatePropNames, "showAllTracks", "showTrackList"]);
111
122
 
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";
123
+ 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 transform: rotateX(0deg);\n perspective: 100px;\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 border: 1px black outset;\n}\n\n.PianoRollKeys-module_white__fR2Lm {\n background: white;\n border-top-width: 0.5px;\n border-bottom-width: 0.5px;\n border-top-right-radius: 4%;\n border-bottom-right-radius: 4%;\n}\n\n.PianoRollKeys-module_down__GcNeZ {\n transition: none;\n background: red;\n transform: rotateX(0deg) rotateY(20deg);\n}\n";
113
124
  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"};
114
125
  styleInject(css_248z$4);
115
126
 
@@ -352,7 +363,7 @@ const PianoRollKeys = () => {
352
363
  return web.createComponent(solidJs.Index, {
353
364
  each: keys,
354
365
  children: key => {
355
- const isDown = solidJs.createMemo(() => context.pressedKeys.includes(key().number));
366
+ const isDown = solidJs.createMemo(() => context.isKeyDown(context.selectedTrackIndex, key().number));
356
367
  const virtualDimensions = solidJs.createMemo(() => verticalViewPort().calculatePixelDimensions(127 - key().number, 1));
357
368
  const previousIsBlack = blackKeys.includes((key().number - 1) % 12);
358
369
  const nextIsBlack = blackKeys.includes((key().number + 1) % 12);
@@ -364,69 +375,47 @@ const PianoRollKeys = () => {
364
375
  const _el$2 = _tmpl$$6.cloneNode(true);
365
376
  _el$2.addEventListener("mouseleave", () => {
366
377
  if (isMouseDown()) {
367
- context.onNoteUp(key().number);
378
+ context.onNoteUp(context.selectedTrackIndex, key().number);
368
379
  }
369
380
  });
370
381
  _el$2.addEventListener("mouseenter", () => {
371
382
  if (isMouseDown()) {
372
- context.onNoteDown(key().number);
383
+ context.onNoteDown(context.selectedTrackIndex, key().number);
373
384
  }
374
385
  });
375
386
  _el$2.$$mouseup = () => {
376
- context.onNoteUp(key().number);
387
+ context.onNoteUp(context.selectedTrackIndex, key().number);
377
388
  };
378
389
  _el$2.$$mousedown = () => {
379
390
  setIsMouseDown(true);
380
- context.onNoteDown(key().number);
391
+ context.onNoteDown(context.selectedTrackIndex, key().number);
381
392
  };
382
- web.insert(_el$2, web.createComponent(solidJs.Show, {
383
- get when() {
384
- return key().isBlack && false;
385
- },
386
- get children() {
387
- const _el$3 = _tmpl$$6.cloneNode(true);
388
- web.effect(_p$ => {
389
- const _v$3 = styles$4["black-separator"],
390
- _v$4 = `${virtualDimensions().offset}px`,
391
- _v$5 = `${virtualDimensions().size / 2 - 0.25}px`;
392
- _v$3 !== _p$._v$3 && web.className(_el$3, _p$._v$3 = _v$3);
393
- _v$4 !== _p$._v$4 && _el$3.style.setProperty("top", _p$._v$4 = _v$4);
394
- _v$5 !== _p$._v$5 && _el$3.style.setProperty("height", _p$._v$5 = _v$5);
395
- return _p$;
396
- }, {
397
- _v$3: undefined,
398
- _v$4: undefined,
399
- _v$5: undefined
400
- });
401
- return _el$3;
402
- }
403
- }));
404
393
  web.effect(_p$ => {
405
- const _v$6 = {
394
+ const _v$3 = {
406
395
  [styles$4["Key"]]: true,
407
396
  [styles$4["black"]]: key().isBlack,
408
397
  [styles$4["white"]]: !key().isBlack,
409
398
  [styles$4["down"]]: isDown()
410
399
  },
411
- _v$7 = key().name,
412
- _v$8 = key().number % 12,
413
- _v$9 = `${virtualDimensions().offset - (!key().isBlack && nextIsBlack ? virtualDimensions().size / 2 : 0)}px`,
414
- _v$10 = `${virtualDimensions().size + (!key().isBlack && nextIsBlack ? virtualDimensions().size / 2 : 0) + (!key().isBlack && previousIsBlack ? virtualDimensions().size / 2 : 0)}px`,
415
- _v$11 = [`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() && `0px 0px ${Math.min(virtualDimensions().size / 8, 2)}px ${Math.min(virtualDimensions().size / 20, 2)}px rgba(0, 0, 0, 0.5) inset`].filter(item => !!item).join(", ");
416
- _p$._v$6 = web.classList(_el$2, _v$6, _p$._v$6);
417
- _v$7 !== _p$._v$7 && web.setAttribute(_el$2, "title", _p$._v$7 = _v$7);
418
- _v$8 !== _p$._v$8 && web.setAttribute(_el$2, "data-index", _p$._v$8 = _v$8);
419
- _v$9 !== _p$._v$9 && _el$2.style.setProperty("top", _p$._v$9 = _v$9);
420
- _v$10 !== _p$._v$10 && _el$2.style.setProperty("height", _p$._v$10 = _v$10);
421
- _v$11 !== _p$._v$11 && _el$2.style.setProperty("box-shadow", _p$._v$11 = _v$11);
400
+ _v$4 = key().name,
401
+ _v$5 = key().number % 12,
402
+ _v$6 = `${virtualDimensions().offset - virtualDimensions().size * (!key().isBlack ? nextIsBlack ? 1 / 2 : 0 : 0)}px`,
403
+ _v$7 = `${virtualDimensions().size + (!key().isBlack && nextIsBlack ? virtualDimensions().size / 2 : 0) + (!key().isBlack && previousIsBlack ? virtualDimensions().size / 2 : 0)}px`,
404
+ _v$8 = [`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() && `0px 0px ${Math.min(virtualDimensions().size / 8, 2)}px ${Math.min(virtualDimensions().size / 20, 2)}px rgba(0, 0, 0, 0.5) inset`].filter(item => !!item).join(", ");
405
+ _p$._v$3 = web.classList(_el$2, _v$3, _p$._v$3);
406
+ _v$4 !== _p$._v$4 && web.setAttribute(_el$2, "title", _p$._v$4 = _v$4);
407
+ _v$5 !== _p$._v$5 && web.setAttribute(_el$2, "data-index", _p$._v$5 = _v$5);
408
+ _v$6 !== _p$._v$6 && _el$2.style.setProperty("top", _p$._v$6 = _v$6);
409
+ _v$7 !== _p$._v$7 && _el$2.style.setProperty("height", _p$._v$7 = _v$7);
410
+ _v$8 !== _p$._v$8 && _el$2.style.setProperty("box-shadow", _p$._v$8 = _v$8);
422
411
  return _p$;
423
412
  }, {
413
+ _v$3: undefined,
414
+ _v$4: undefined,
415
+ _v$5: undefined,
424
416
  _v$6: undefined,
425
417
  _v$7: undefined,
426
- _v$8: undefined,
427
- _v$9: undefined,
428
- _v$10: undefined,
429
- _v$11: undefined
418
+ _v$8: undefined
430
419
  });
431
420
  return _el$2;
432
421
  }
@@ -469,72 +458,96 @@ const PianoRollNotes = props => {
469
458
  const verticalViewPort = solidJs.createMemo(() => useViewPortDimension(context.mode === "keys" ? "vertical" : "verticalTracks"));
470
459
  const horizontalViewPort = solidJs.createMemo(() => useViewPortDimension("horizontal"));
471
460
  const gridDivisionTicks = solidJs.createMemo(() => context.ppq * 4 / context.gridDivision);
461
+ const [isDragging, setIsDragging] = solidJs.createSignal(false);
462
+ const [noteDragMode, setNoteDragMode] = solidJs.createSignal();
463
+ const [currentNoteIndex, setCurrentNoteIndex] = solidJs.createSignal(-1);
464
+ const [currentNoteTrackIndex, setCurrentNoteTrackIndex] = solidJs.createSignal(-1);
465
+ const [diffPosition, setDiffPosition] = solidJs.createSignal(0);
466
+ const [getInitialNote, setInitialNote] = solidJs.createSignal();
472
467
  const snapValueToGridIfEnabled = (value, altKey) => context.snapToGrid && !altKey ? Math.round(value / gridDivisionTicks()) * gridDivisionTicks() : value;
473
- const insertOrUpdateNote = event => {
474
- const position = horizontalViewPort().calculatePosition(event.clientX);
475
- const existingNote = currentNote();
476
- const midi = context.mode === "keys" ? 127 - Math.floor(verticalViewPort().calculatePosition(event.clientY)) : existingNote?.midi ?? 60;
477
- const targetTrackIndex = context.mode === "tracks" ? clamp(Math.floor(verticalViewPort().calculatePosition(event.clientY)), 0, context.tracks.length - 1) : context.selectedTrackIndex ?? 0;
478
- const eventPositionTicks = Math.floor(position / gridDivisionTicks()) * gridDivisionTicks();
479
- const velocity = 127;
480
- const ticks = existingNote?.ticks ?? eventPositionTicks;
481
- const durationTicks = existingNote?.ticks ? eventPositionTicks - existingNote?.ticks : gridDivisionTicks();
482
- const note = {
468
+ const calculateNoteDragValues = event => {
469
+ const targetTrackIndex = context.mode === "tracks" ? clamp(Math.floor(verticalViewPort().calculatePosition(event.clientY)), 0, context.tracks.length - 1) : currentNoteTrackIndex() > -1 ? currentNoteTrackIndex() : context.selectedTrackIndex;
470
+ const midi = context.mode === "keys" ? Math.floor(128 - verticalViewPort().calculatePosition(event.clientY)) : getInitialNote()?.midi ?? 60;
471
+ const horiontalPosition = horizontalViewPort().calculatePosition(event.clientX);
472
+ return {
473
+ targetTrackIndex,
483
474
  midi,
484
- ticks,
485
- durationTicks,
486
- velocity
475
+ horiontalPosition
487
476
  };
488
- if (existingNote) {
489
- context.onNoteChange?.(currentNoteTrackIndex(), currentNoteIndex(), note);
490
- return currentNoteIndex();
477
+ };
478
+ const handleMouseMove = mouseMoveEvent => {
479
+ const note = getInitialNote();
480
+ if (!note) return;
481
+ const {
482
+ targetTrackIndex,
483
+ midi,
484
+ horiontalPosition
485
+ } = calculateNoteDragValues(mouseMoveEvent);
486
+ const ticks = snapValueToGridIfEnabled(horiontalPosition - diffPosition(), mouseMoveEvent.altKey);
487
+ const updatedNote = {
488
+ ...note,
489
+ midi,
490
+ ...(noteDragMode() === "move" && {
491
+ ticks
492
+ }),
493
+ ...(noteDragMode() === "trimStart" && {
494
+ ticks: ticks < note.ticks + note.durationTicks ? ticks : note.ticks + note.durationTicks,
495
+ durationTicks: ticks < note.ticks + note.durationTicks ? note.ticks + note.durationTicks - ticks : snapValueToGridIfEnabled(horiontalPosition - note.ticks, mouseMoveEvent.altKey)
496
+ }),
497
+ ...(noteDragMode() === "trimEnd" && {
498
+ ticks: ticks < note.ticks ? ticks : note.ticks,
499
+ durationTicks: ticks < note.ticks ? note.ticks - ticks : snapValueToGridIfEnabled(horiontalPosition - note.ticks, mouseMoveEvent.altKey)
500
+ })
501
+ };
502
+ const previousTrackIndex = currentNoteTrackIndex();
503
+ const previousNoteIndex = currentNoteIndex();
504
+ if (targetTrackIndex === previousTrackIndex) {
505
+ context.onNoteChange?.(previousTrackIndex, previousNoteIndex, updatedNote);
491
506
  } else {
492
- return context.onInsertNote?.(targetTrackIndex, note) ?? -1;
507
+ if (context.onInsertNote) {
508
+ context.onRemoveNote?.(previousTrackIndex, previousNoteIndex);
509
+ const newNoteIndex = context.onInsertNote(targetTrackIndex, updatedNote);
510
+ setCurrentNoteTrackIndex(targetTrackIndex);
511
+ setCurrentNoteIndex(newNoteIndex);
512
+ }
493
513
  }
494
514
  };
495
- const [isDragging, setIsDragging] = solidJs.createSignal(false);
496
- const [noteDragMode, setNoteDragMode] = solidJs.createSignal();
497
- const [currentNoteIndex, setCurrentNoteIndex] = solidJs.createSignal(-1);
498
- const [currentNoteTrackIndex, setCurrentNoteTrackIndex] = solidJs.createSignal(-1);
499
- const [isMouseDown, setIsMouseDown] = solidJs.createSignal(false);
500
- const currentNote = solidJs.createMemo(() => context.tracks[currentNoteTrackIndex()]?.notes[currentNoteIndex()]);
515
+ const stopDragging = () => {
516
+ window.removeEventListener("mousemove", handleMouseMove);
517
+ window.removeEventListener("mouseup", stopDragging);
518
+ setIsDragging(false);
519
+ };
520
+ const startDragging = () => {
521
+ window.addEventListener("mousemove", handleMouseMove);
522
+ window.addEventListener("mouseup", stopDragging);
523
+ };
501
524
  const getClasses = noteDragMode => {
502
525
  return noteDragMode ? [styles$2.Note, styles$2[noteDragMode]] : [styles$2.Note];
503
526
  };
504
527
  return (() => {
505
528
  const _el$ = _tmpl$$5.cloneNode(true);
506
- _el$.$$click = event => {
507
- if (currentNote()) {
508
- setCurrentNoteIndex(-1);
509
- return;
510
- }
511
- if (!event.altKey) return;
512
- insertOrUpdateNote(event);
513
- };
514
- _el$.$$dblclick = event => {
515
- insertOrUpdateNote(event);
516
- };
517
- _el$.$$mouseup = event => {
518
- setIsMouseDown(false);
519
- if (!event.altKey) return;
520
- insertOrUpdateNote(event);
521
- };
522
- _el$.$$mousemove = event => {
523
- if (isDragging()) return;
524
- if (!isMouseDown()) {
525
- setNoteDragMode(undefined);
526
- return;
527
- }
528
- const index = insertOrUpdateNote(event);
529
- setCurrentNoteIndex(index);
530
- };
531
- _el$.$$mousedown = event => {
532
- solidJs.batch(() => {
533
- setIsMouseDown(true);
534
- const index = insertOrUpdateNote(event);
535
- setCurrentNoteTrackIndex(context.selectedTrackIndex ?? 0);
536
- setCurrentNoteIndex(index);
537
- });
529
+ _el$.$$mousedown = mouseDownEvent => {
530
+ const {
531
+ targetTrackIndex,
532
+ midi,
533
+ horiontalPosition
534
+ } = calculateNoteDragValues(mouseDownEvent);
535
+ const ticks = snapValueToGridIfEnabled(horiontalPosition, mouseDownEvent.altKey);
536
+ const durationTicks = gridDivisionTicks();
537
+ const newNote = {
538
+ midi,
539
+ ticks,
540
+ durationTicks,
541
+ velocity: 100
542
+ };
543
+ const newNoteIndex = context.onInsertNote(targetTrackIndex, newNote);
544
+ setIsDragging(true);
545
+ setCurrentNoteTrackIndex(targetTrackIndex);
546
+ setCurrentNoteIndex(newNoteIndex);
547
+ setInitialNote(newNote);
548
+ setDiffPosition(0);
549
+ setNoteDragMode("trimEnd");
550
+ startDragging();
538
551
  };
539
552
  const _ref$ = props.ref;
540
553
  typeof _ref$ === "function" ? web.use(_ref$, _el$) : props.ref = _el$;
@@ -563,55 +576,13 @@ const PianoRollNotes = props => {
563
576
  const _el$2 = _tmpl$$5.cloneNode(true);
564
577
  _el$2.$$mousedown = event => {
565
578
  event.stopPropagation();
579
+ const initialPosition = horizontalViewPort().calculatePosition(event.clientX);
580
+ setDiffPosition(noteDragMode() === "trimEnd" ? -(note.ticks + note.durationTicks - initialPosition) : initialPosition - note.ticks);
566
581
  setIsDragging(true);
567
582
  setCurrentNoteIndex(noteIndex());
568
583
  setCurrentNoteTrackIndex(trackIndex());
569
- const initialPosition = horizontalViewPort().calculatePosition(event.clientX);
570
- const diffPosition = initialPosition - note.ticks;
571
- const handleMouseMove = mouseMoveEvent => {
572
- const note = currentNote();
573
- if (!note) return;
574
- const ticks = snapValueToGridIfEnabled(Math.max(horizontalViewPort().calculatePosition(mouseMoveEvent.clientX) - diffPosition, 0), mouseMoveEvent.altKey);
575
- const updatedNote = {
576
- ...note,
577
- ...(noteDragMode() === "move" && context.mode === "keys" && {
578
- midi: Math.round(127 - verticalViewPort().calculatePosition(mouseMoveEvent.clientY))
579
- }),
580
- ...((noteDragMode() === "move" || noteDragMode() === "trimStart") && {
581
- ticks
582
- }),
583
- ...(noteDragMode() === "trimStart" && {
584
- durationTicks: note.durationTicks + note.ticks - ticks
585
- }),
586
- ...(noteDragMode() === "trimEnd" && {
587
- durationTicks: snapValueToGridIfEnabled(horizontalViewPort().calculatePosition(mouseMoveEvent.clientX) - note.ticks, mouseMoveEvent.altKey)
588
- })
589
- };
590
- const previousTrackIndex = currentNoteTrackIndex();
591
- const previousNoteIndex = currentNoteIndex();
592
- const targetTrackIndex = context.mode === "tracks" ? clamp(Math.floor(verticalViewPort().calculatePosition(mouseMoveEvent.clientY)), 0, context.tracks.length - 1) : previousTrackIndex;
593
- if (targetTrackIndex === previousTrackIndex) {
594
- context.onNoteChange?.(previousTrackIndex, previousNoteIndex, updatedNote);
595
- } else {
596
- solidJs.batch(() => {
597
- if (context.onInsertNote) {
598
- context.onRemoveNote?.(previousTrackIndex, previousNoteIndex);
599
- const newNoteIndex = context.onInsertNote(targetTrackIndex, updatedNote);
600
- setCurrentNoteTrackIndex(targetTrackIndex);
601
- setCurrentNoteIndex(newNoteIndex);
602
- }
603
- });
604
- }
605
- };
606
- const handleMouseUp = () => {
607
- setIsDragging(false);
608
- setCurrentNoteIndex(-1);
609
- setCurrentNoteTrackIndex(-1);
610
- window.removeEventListener("mousemove", handleMouseMove);
611
- window.removeEventListener("mouseup", handleMouseUp);
612
- };
613
- window.addEventListener("mousemove", handleMouseMove);
614
- window.addEventListener("mouseup", handleMouseUp);
584
+ setInitialNote(note);
585
+ startDragging();
615
586
  };
616
587
  _el$2.$$dblclick = event => {
617
588
  event.stopPropagation();
@@ -663,7 +634,7 @@ const PianoRollNotes = props => {
663
634
  return _el$;
664
635
  })();
665
636
  };
666
- web.delegateEvents(["mousedown", "mousemove", "mouseup", "dblclick", "click"]);
637
+ web.delegateEvents(["mousedown", "mousemove", "dblclick"]);
667
638
 
668
639
  var css_248z$1 = ".PianoRollGrid-module_PianoRollGrid__tG119 {\n position: relative;\n width: 100%;\n height: 100%;\n}\n\n.PianoRollGrid-module_PianoRollGrid-Row__nRMCs {\n position: absolute;\n border-style: solid;\n border-color: gray;\n}\n\n.PianoRollGrid-module_PianoRollGrid-Time__jLz3E {\n position: absolute;\n box-sizing: border-box;\n top: 0px;\n height: 100%;\n border-left-style: solid;\n border-left-width: 0.5px;\n}\n";
669
640
  var styles$1 = {"PianoRollGrid":"PianoRollGrid-module_PianoRollGrid__tG119","PianoRollGrid-Row":"PianoRollGrid-module_PianoRollGrid-Row__nRMCs","PianoRollGrid-Time":"PianoRollGrid-module_PianoRollGrid-Time__jLz3E"};
@@ -902,8 +873,8 @@ const ZoomSliderControl = props => {
902
873
  })();
903
874
  };
904
875
 
905
- var css_248z = ".PianoRollTrackList-module_PianoRollTrackList__pyuxQ {\n position: relative;\n height: 100%;\n flex: 1;\n}\n\n.PianoRollTrackList-module_Track__VZFIg {\n border-width: 0px;\n position: absolute;\n box-sizing: border-box;\n width: 100%;\n border-color: #000;\n border-style: solid;\n border-right-width: 1px;\n border-bottom-width: 1px;\n}\n";
906
- var styles = {"PianoRollTrackList":"PianoRollTrackList-module_PianoRollTrackList__pyuxQ","Track":"PianoRollTrackList-module_Track__VZFIg"};
876
+ var css_248z = ".PianoRollTrackList-module_PianoRollTrackList__-sDf0 {\n position: relative;\n height: 100%;\n flex: 1;\n}\n\n.PianoRollTrackList-module_Track__mZP1K {\n border-width: 0px;\n position: absolute;\n box-sizing: border-box;\n width: 100%;\n border-color: #000;\n border-style: solid;\n border-right-width: 1px;\n border-bottom-width: 1px;\n cursor: \"pointer\";\n background: \"lightgrey\";\n}\n.PianoRollTrackList-module_Track__mZP1K.PianoRollTrackList-module_selected__0b-mf {\n background: \"gray\";\n}";
877
+ var styles = {"PianoRollTrackList":"PianoRollTrackList-module_PianoRollTrackList__-sDf0","Track":"PianoRollTrackList-module_Track__mZP1K","selected":"PianoRollTrackList-module_selected__0b-mf"};
907
878
  styleInject(css_248z);
908
879
 
909
880
  const _tmpl$$2 = /*#__PURE__*/web.template(`<div></div>`, 2),
@@ -927,29 +898,26 @@ const PianoRollTrackList = () => {
927
898
  const _el$2 = _tmpl$2$1.cloneNode(true),
928
899
  _el$3 = _el$2.firstChild;
929
900
  _el$2.$$click = () => context.onSelectedTrackIndexChange?.(index);
930
- _el$2.style.setProperty("cursor", "pointer");
931
901
  web.insert(_el$2, index, _el$3);
932
902
  web.insert(_el$2, () => track().name || "[unnamed track]", null);
933
903
  web.effect(_p$ => {
934
904
  const _v$ = {
935
- [styles["Track"]]: true
905
+ [styles["Track"]]: true,
906
+ [styles["selected"]]: index === context.selectedTrackIndex
936
907
  },
937
908
  _v$2 = track().name,
938
909
  _v$3 = `${virtualDimensions().offset}px`,
939
- _v$4 = `${virtualDimensions().size}px`,
940
- _v$5 = index === context.selectedTrackIndex ? "gray" : "lightgrey";
910
+ _v$4 = `${virtualDimensions().size}px`;
941
911
  _p$._v$ = web.classList(_el$2, _v$, _p$._v$);
942
912
  _v$2 !== _p$._v$2 && web.setAttribute(_el$2, "title", _p$._v$2 = _v$2);
943
913
  _v$3 !== _p$._v$3 && _el$2.style.setProperty("top", _p$._v$3 = _v$3);
944
914
  _v$4 !== _p$._v$4 && _el$2.style.setProperty("height", _p$._v$4 = _v$4);
945
- _v$5 !== _p$._v$5 && _el$2.style.setProperty("background", _p$._v$5 = _v$5);
946
915
  return _p$;
947
916
  }, {
948
917
  _v$: undefined,
949
918
  _v$2: undefined,
950
919
  _v$3: undefined,
951
- _v$4: undefined,
952
- _v$5: undefined
920
+ _v$4: undefined
953
921
  });
954
922
  return _el$2;
955
923
  }
@@ -1034,9 +1002,6 @@ const PianoRoll = allProps => {
1034
1002
  orientation: "vertical",
1035
1003
  dimensionName: "verticalTracks"
1036
1004
  }), _el$3);
1037
- _el$3.style.setProperty("display", "flex");
1038
- _el$3.style.setProperty("width", "30%");
1039
- _el$3.style.setProperty("max-width", "250px");
1040
1005
  web.insert(_el$3, web.createComponent(solidJs.Show, {
1041
1006
  get when() {
1042
1007
  return context.showTrackList;
@@ -1078,7 +1043,16 @@ const PianoRoll = allProps => {
1078
1043
  return context.mode !== "keys";
1079
1044
  }
1080
1045
  }), null);
1081
- web.effect(() => web.className(_el$2, styles$5.PianoRollContainer));
1046
+ web.effect(_p$ => {
1047
+ const _v$ = styles$5.PianoRollContainer,
1048
+ _v$2 = styles$5.PianoRollLeftColumn;
1049
+ _v$ !== _p$._v$ && web.className(_el$2, _p$._v$ = _v$);
1050
+ _v$2 !== _p$._v$2 && web.className(_el$3, _p$._v$2 = _v$2);
1051
+ return _p$;
1052
+ }, {
1053
+ _v$: undefined,
1054
+ _v$2: undefined
1055
+ });
1082
1056
  return _el$2;
1083
1057
  })(), web.createComponent(ZoomSliderControl, {
1084
1058
  orientation: "horizontal",
@@ -1098,19 +1072,15 @@ const PianoRoll = allProps => {
1098
1072
 
1099
1073
  const _tmpl$ = /*#__PURE__*/web.template(`<div class="PlayHead"></div>`, 2);
1100
1074
  const PlayHead = allProps => {
1101
- const propsWithDefauls = solidJs.mergeProps({
1102
- playHeadPosition: 0,
1103
- sync: false
1104
- }, allProps);
1105
- const [props, divProps] = solidJs.splitProps(propsWithDefauls, ["playHeadPosition", "sync", "onPlayHeadPositionChange", "onPositionChange"]);
1106
- const viewPort = useViewPortDimension("horizontal");
1075
+ const [props, divProps] = solidJs.splitProps(allProps, ["position", "sync", "onPositionChange", "dimensionName"]);
1076
+ const viewPort = useViewPortDimension(props.dimensionName ?? "horizontal");
1107
1077
  solidJs.createEffect(() => {
1108
1078
  if (!props.sync) return;
1109
1079
  const maxPosition = viewPort.range;
1110
- const newPosition = clamp(props.playHeadPosition - viewPort.range / viewPort.zoom / 2, 0, maxPosition);
1111
- props.onPositionChange?.(newPosition);
1080
+ const newPosition = clamp(props.position - viewPort.range / viewPort.zoom / 2, 0, maxPosition);
1081
+ viewPort.onPositionChange?.(newPosition);
1112
1082
  });
1113
- const leftPosition = solidJs.createMemo(() => viewPort.calculatePixelOffset(props.playHeadPosition));
1083
+ const leftPosition = solidJs.createMemo(() => viewPort.calculatePixelOffset(props.position));
1114
1084
  return (() => {
1115
1085
  const _el$ = _tmpl$.cloneNode(true);
1116
1086
  web.spread(_el$, web.mergeProps(divProps, {
@@ -1132,7 +1102,7 @@ const PlayHead = allProps => {
1132
1102
  clientX
1133
1103
  }) => {
1134
1104
  const newPosition = viewPort.calculatePosition(clientX);
1135
- props.onPlayHeadPositionChange?.(newPosition);
1105
+ props.onPositionChange?.(newPosition);
1136
1106
  };
1137
1107
  const handleMouseUp = () => {
1138
1108
  window.removeEventListener("mousemove", handleMouseMove);