Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | import React, { useCallback } from "react"; import { PatternCell } from "shared/lib/uge/types"; import trackerActions from "store/features/tracker/trackerActions"; import trackerDocumentActions from "store/features/trackerDocument/trackerDocumentActions"; import editorActions from "store/features/editor/editorActions"; import { useAppDispatch, useAppSelector } from "store/hooks"; import { StyledPianoRollEffectCell, StyledPianoRollEffectRow } from "./style"; import { PIANO_ROLL_CELL_SIZE } from "consts"; interface PianoRollEffectRowProps { patternId: number; sequenceId: number; channelId: number; } type EffectCellChanges = { effectcode: number | null; effectparam: number | null; }; const computeEffectChanges = ( cell?: PatternCell, lastCell?: PatternCell, ): EffectCellChanges | null => { Iif (!cell) { return null; } return { effectcode: cell.effectcode !== null ? cell.effectcode : (lastCell?.effectcode ?? 0), effectparam: cell.effectparam !== null ? cell.effectparam : (lastCell?.effectparam ?? 0), }; }; const clearEffect = (): EffectCellChanges => ({ effectcode: null, effectparam: null, }); const selectEffectCell = (sequenceId: number, column: number) => [ editorActions.setSelectedSequence(sequenceId), trackerActions.setSelectedEffectCell(column), ]; const hasEffect = (cell?: PatternCell) => Boolean(cell && (cell.effectcode !== null || cell.effectparam !== null)); export const PianoRollEffectRow = React.memo( ({ patternId, sequenceId, channelId }: PianoRollEffectRowProps) => { const dispatch = useAppDispatch(); const tool = useAppSelector((state) => state.tracker.tool); const playing = useAppSelector((state) => state.tracker.playing); const selectedEffectCell = useAppSelector( (state) => state.tracker.selectedEffectCell, ); const selectedSequence = useAppSelector( (state) => state.editor.selectedSequence, ); const songDocument = useAppSelector( (state) => state.trackerDocument.present.song, ); const renderPattern = songDocument?.patterns[patternId]; const handleMouseDown = useCallback( (e: React.MouseEvent<HTMLDivElement>) => { Iif (!renderPattern) return; const col = Math.floor(e.nativeEvent.offsetX / PIANO_ROLL_CELL_SIZE); const cell = renderPattern[col]?.[channelId] as PatternCell | undefined; const lastPatternId = songDocument?.sequence[selectedSequence]; const lastCell = lastPatternId !== undefined && selectedEffectCell !== null ? (songDocument?.patterns[lastPatternId]?.[selectedEffectCell]?.[ channelId ] as PatternCell | undefined) : undefined; if (e.button === 0 && tool !== "eraser") { const changes = computeEffectChanges(cell, lastCell); Iif (changes) { const selectionActions = selectEffectCell(sequenceId, col); dispatch( trackerDocumentActions.editPatternCell({ patternId, cell: [col, channelId], changes, }), ); selectionActions.forEach((action) => { dispatch(action); }); } } else Iif (e.button === 2 || (tool === "eraser" && e.button === 0)) { Iif (hasEffect(cell)) { dispatch( trackerDocumentActions.editPatternCell({ patternId, cell: [col, channelId], changes: clearEffect(), }), ); } } }, [ renderPattern, channelId, tool, dispatch, patternId, sequenceId, selectedEffectCell, selectedSequence, songDocument, ], ); return ( <StyledPianoRollEffectRow onMouseDown={!playing ? handleMouseDown : undefined} > {renderPattern?.map((column: PatternCell[], columnIdx: number) => { const cell = column[channelId]; const isSelected = selectedSequence === sequenceId && selectedEffectCell === columnIdx; Iif ( !cell || (cell.effectcode === null && cell.effectparam === null) ) { return null; } return ( <StyledPianoRollEffectCell key={`fx_${columnIdx}_${channelId}`} data-type="note" data-column={columnIdx} $isSelected={isSelected} style={{ left: `${columnIdx * PIANO_ROLL_CELL_SIZE}px` }} > <span>{cell.effectcode?.toString(16).toUpperCase()}</span> </StyledPianoRollEffectCell> ); })} </StyledPianoRollEffectRow> ); }, ); |