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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | import React, { useCallback, useMemo } from "react"; import { PatternCell } from "shared/lib/uge/types"; import trackerActions from "store/features/tracker/trackerActions"; import trackerDocumentActions from "store/features/trackerDocument/trackerDocumentActions"; import { useAppDispatch, useAppSelector, useAppStore } from "store/hooks"; import { StyledPianoRollEffectCell, StyledPianoRollEffectRow } from "./style"; import { PIANO_ROLL_CELL_SIZE } from "consts"; interface PianoRollEffectRowProps { patternId: number; sequenceId: number; channelId: 0 | 1 | 2 | 3; } 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 hasEffect = (cell?: PatternCell) => Boolean(cell && (cell.effectCode !== null || cell.effectParam !== null)); export const PianoRollEffectRow = React.memo( ({ sequenceId, patternId, channelId }: PianoRollEffectRowProps) => { const store = useAppStore(); 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 selectedPatternCells = useAppSelector( (state) => state.tracker.selectedPatternCells, ); const selectedRowIds = useMemo(() => { return new Set( selectedPatternCells .filter( (cell) => cell.sequenceId === sequenceId && cell.channelId === channelId, ) .map((cell) => cell.rowId), ); }, [channelId, selectedPatternCells, sequenceId]); const pattern = useAppSelector( (state) => state.trackerDocument.present.song?.patterns[patternId], ); const handleMouseDown = useCallback( (e: React.MouseEvent<HTMLDivElement>) => { Iif (!pattern) return; const state = store.getState(); const songDocument = state.trackerDocument.present.song; const col = Math.floor(e.nativeEvent.offsetX / PIANO_ROLL_CELL_SIZE); const cell = pattern[col]; const lastCell = selectedEffectCell !== null ? songDocument?.patterns[selectedEffectCell.patternId]?.[ selectedEffectCell.rowId ] : undefined; if (e.button === 0 && tool !== "eraser") { const changes = computeEffectChanges(cell, lastCell); Iif (changes) { Iif (tool === "pencil") { dispatch( trackerDocumentActions.editPatternCell({ patternId, rowId: col, changes, }), ); } dispatch( trackerActions.setSelectedEffectCell({ sequenceId, patternId, rowId: col, channelId, }), ); dispatch( trackerActions.setSelectedPatternCells([ { sequenceId, rowId: col, channelId, }, ]), ); } } else Iif (e.button === 2 || (tool === "eraser" && e.button === 0)) { Iif (hasEffect(cell)) { dispatch( trackerDocumentActions.editPatternCell({ patternId, rowId: col, changes: clearEffect(), }), ); } } }, [ pattern, store, channelId, selectedEffectCell, tool, dispatch, sequenceId, patternId, ], ); return ( <StyledPianoRollEffectRow onMouseDown={!playing ? handleMouseDown : undefined} > {pattern?.map((cell, columnIdx: number) => { const isSelected = selectedRowIds.has(columnIdx); Iif (!cell || cell.effectCode === null) { return null; } return ( <StyledPianoRollEffectCell key={`fx_${columnIdx}_${channelId}`} data-type="note" data-row={columnIdx} $isSelected={isSelected} style={{ left: `${columnIdx * PIANO_ROLL_CELL_SIZE}px` }} $instrument={cell.instrument ?? undefined} > <span>{cell.effectCode?.toString(16).toUpperCase()}</span> </StyledPianoRollEffectCell> ); })} </StyledPianoRollEffectRow> ); }, ); |