Rename CanvasLogicalWidth to CanvasWidth
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rob Watson 2022-02-04 08:37:39 +01:00
parent 3dcc1edc62
commit a9ea462b41
4 changed files with 28 additions and 44 deletions

View File

@ -13,8 +13,8 @@ import { WaveformCanvas } from './WaveformCanvas';
import { HudCanvas } from './HudCanvas'; import { HudCanvas } from './HudCanvas';
import { Player, PlayState } from './Player'; import { Player, PlayState } from './Player';
import { import {
CanvasLogicalWidth, CanvasWidth,
CanvasLogicalHeight, CanvasHeight,
EmptySelectionAction, EmptySelectionAction,
} from './HudCanvasState'; } from './HudCanvasState';
import { ControlBar } from './ControlBar'; import { ControlBar } from './ControlBar';
@ -95,7 +95,7 @@ function App(): JSX.Element {
console.log('fetching audio...'); console.log('fetching audio...');
const audioProgressStream = service.GetPeaks({ const audioProgressStream = service.GetPeaks({
id: mediaSet.id, id: mediaSet.id,
numBins: CanvasLogicalWidth, numBins: CanvasWidth,
}); });
const peaks = audioProgressStream.pipe(map((progress) => progress.peaks)); const peaks = audioProgressStream.pipe(map((progress) => progress.peaks));
dispatch({ type: 'overviewpeaksloaded', peaks: peaks }); dispatch({ type: 'overviewpeaksloaded', peaks: peaks });
@ -142,7 +142,7 @@ function App(): JSX.Element {
const service = new MediaSetServiceClientImpl(newRPC()); const service = new MediaSetServiceClientImpl(newRPC());
const segment = await service.GetPeaksForSegment({ const segment = await service.GetPeaksForSegment({
id: mediaSet.id, id: mediaSet.id,
numBins: CanvasLogicalWidth, numBins: CanvasWidth,
startFrame: viewport.start, startFrame: viewport.start,
endFrame: viewport.end, endFrame: viewport.end,
}); });
@ -332,15 +332,15 @@ function App(): JSX.Element {
<WaveformCanvas <WaveformCanvas
peaks={overviewPeaks} peaks={overviewPeaks}
channels={mediaSet.audioChannels} channels={mediaSet.audioChannels}
width={CanvasLogicalWidth} width={CanvasWidth}
height={CanvasLogicalHeight} height={CanvasHeight}
strokeStyle="black" strokeStyle="black"
fillStyle="#003300" fillStyle="#003300"
alpha={1} alpha={1}
></WaveformCanvas> ></WaveformCanvas>
<HudCanvas <HudCanvas
width={CanvasLogicalWidth} width={CanvasWidth}
height={CanvasLogicalHeight} height={CanvasHeight}
emptySelectionAction={EmptySelectionAction.SelectPrevious} emptySelectionAction={EmptySelectionAction.SelectPrevious}
styles={{ styles={{
borderLineWidth: 4, borderLineWidth: 4,
@ -349,7 +349,7 @@ function App(): JSX.Element {
positionStrokeStyle: 'red', positionStrokeStyle: 'red',
hoverPositionStrokeStyle: 'transparent', hoverPositionStrokeStyle: 'transparent',
}} }}
position={(position.percent / 100) * CanvasLogicalWidth} position={(position.percent / 100) * CanvasWidth}
selection={viewportCanvas} selection={viewportCanvas}
onSelectionChange={(event) => onSelectionChange={(event) =>
dispatch({ type: 'viewportchanged', event }) dispatch({ type: 'viewportchanged', event })
@ -361,15 +361,15 @@ function App(): JSX.Element {
<WaveformCanvas <WaveformCanvas
peaks={waveformPeaks} peaks={waveformPeaks}
channels={mediaSet.audioChannels} channels={mediaSet.audioChannels}
width={CanvasLogicalWidth} width={CanvasWidth}
height={CanvasLogicalHeight} height={CanvasHeight}
strokeStyle="green" strokeStyle="green"
fillStyle="black" fillStyle="black"
alpha={1} alpha={1}
></WaveformCanvas> ></WaveformCanvas>
<HudCanvas <HudCanvas
width={CanvasLogicalWidth} width={CanvasWidth}
height={CanvasLogicalHeight} height={CanvasHeight}
emptySelectionAction={EmptySelectionAction.SelectNothing} emptySelectionAction={EmptySelectionAction.SelectNothing}
styles={{ styles={{
borderLineWidth: 0, borderLineWidth: 0,
@ -381,7 +381,7 @@ function App(): JSX.Element {
position={frameToWaveformCanvasX( position={frameToWaveformCanvasX(
position.frame, position.frame,
viewport, viewport,
CanvasLogicalWidth CanvasWidth
)} )}
selection={selectionCanvas} selection={selectionCanvas}
onSelectionChange={(event) => onSelectionChange={(event) =>

View File

@ -2,7 +2,7 @@ import { MediaSet } from './generated/media_set';
import { stateReducer, State } from './AppState'; import { stateReducer, State } from './AppState';
import { from } from 'rxjs'; import { from } from 'rxjs';
import { PlayState } from './Player'; import { PlayState } from './Player';
import { CanvasLogicalWidth } from './HudCanvasState'; import { CanvasWidth } from './HudCanvasState';
const initialState: State = { const initialState: State = {
selection: { start: 0, end: 0 }, selection: { start: 0, end: 0 },
@ -10,7 +10,7 @@ const initialState: State = {
overviewPeaks: from([]), overviewPeaks: from([]),
waveformPeaks: from([]), waveformPeaks: from([]),
selectionCanvas: { x1: 0, x2: 0 }, selectionCanvas: { x1: 0, x2: 0 },
viewportCanvas: { x1: 0, x2: CanvasLogicalWidth }, viewportCanvas: { x1: 0, x2: CanvasWidth },
position: { currentTime: 0, frame: 0, percent: 0 }, position: { currentTime: 0, frame: 0, percent: 0 },
audioSrc: '', audioSrc: '',
videoSrc: '', videoSrc: '',

View File

@ -1,7 +1,7 @@
import { MediaSet } from './generated/media_set'; import { MediaSet } from './generated/media_set';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { SelectionChangeEvent } from './HudCanvas'; import { SelectionChangeEvent } from './HudCanvas';
import { CanvasRange, SelectionMode, CanvasLogicalWidth } from './HudCanvasState'; import { CanvasRange, SelectionMode, CanvasWidth } from './HudCanvasState';
import { PlayState } from './Player'; import { PlayState } from './Player';
import { zoomViewportIn, zoomViewportOut } from './helpers/zoom'; import { zoomViewportIn, zoomViewportOut } from './helpers/zoom';
import frameToWaveformCanvasX from './helpers/frameToWaveformCanvasX'; import frameToWaveformCanvasX from './helpers/frameToWaveformCanvasX';
@ -160,7 +160,7 @@ function handleMediaSetLoaded(
{ mediaSet }: MediaSetLoadedAction { mediaSet }: MediaSetLoadedAction
): State { ): State {
const numFrames = Math.min( const numFrames = Math.min(
Math.round(mediaSet.audioFrames / CanvasLogicalWidth) * Math.round(mediaSet.audioFrames / CanvasWidth) *
initialViewportCanvasPixels, initialViewportCanvasPixels,
mediaSet.audioFrames mediaSet.audioFrames
); );
@ -218,12 +218,8 @@ function setViewport(state: State, { viewport }: SetViewportAction): State {
...state, ...state,
viewport: viewport, viewport: viewport,
viewportCanvas: { viewportCanvas: {
x1: Math.round( x1: Math.round((viewport.start / mediaSet.audioFrames) * CanvasWidth),
(viewport.start / mediaSet.audioFrames) * CanvasLogicalWidth x2: Math.round((viewport.end / mediaSet.audioFrames) * CanvasWidth),
),
x2: Math.round(
(viewport.end / mediaSet.audioFrames) * CanvasLogicalWidth
),
}, },
selectionCanvas: selectionToWaveformCanvasRange(selection, viewport), selectionCanvas: selectionToWaveformCanvasRange(selection, viewport),
}; };
@ -291,12 +287,8 @@ function handleViewportChanged(
} }
const newViewport = { const newViewport = {
start: Math.round( start: Math.round(mediaSet.audioFrames * (canvasRange.x1 / CanvasWidth)),
mediaSet.audioFrames * (canvasRange.x1 / CanvasLogicalWidth) end: Math.round(mediaSet.audioFrames * (canvasRange.x2 / CanvasWidth)),
),
end: Math.round(
mediaSet.audioFrames * (canvasRange.x2 / CanvasLogicalWidth)
),
}; };
return { return {
@ -323,7 +315,7 @@ function handleWaveformSelectionChanged(
return state; return state;
} }
const framesPerPixel = (viewport.end - viewport.start) / CanvasLogicalWidth; const framesPerPixel = (viewport.end - viewport.start) / CanvasWidth;
const newSelection = { const newSelection = {
start: Math.round(viewport.start + canvasRange.x1 * framesPerPixel), start: Math.round(viewport.start + canvasRange.x1 * framesPerPixel),
end: Math.round(viewport.start + canvasRange.x2 * framesPerPixel), end: Math.round(viewport.start + canvasRange.x2 * framesPerPixel),
@ -415,20 +407,12 @@ function selectionToWaveformCanvasRange(
selection: FrameRange, selection: FrameRange,
viewport: FrameRange viewport: FrameRange
): CanvasRange { ): CanvasRange {
const x1 = frameToWaveformCanvasX( const x1 = frameToWaveformCanvasX(selection.start, viewport, CanvasWidth);
selection.start, const x2 = frameToWaveformCanvasX(selection.end, viewport, CanvasWidth);
viewport,
CanvasLogicalWidth
);
const x2 = frameToWaveformCanvasX(
selection.end,
viewport,
CanvasLogicalWidth
);
if (x1 == x2) { if (x1 == x2) {
return { x1: 0, x2: 0 }; return { x1: 0, x2: 0 };
} }
return { x1: x1 || 0, x2: x2 || CanvasLogicalWidth }; return { x1: x1 || 0, x2: x2 || CanvasWidth };
} }

View File

@ -1,7 +1,7 @@
import constrainNumeric from './helpers/constrainNumeric'; import constrainNumeric from './helpers/constrainNumeric';
export const CanvasLogicalWidth = 2000; export const CanvasWidth = 2000;
export const CanvasLogicalHeight = 500; export const CanvasHeight = 500;
export interface CanvasRange { export interface CanvasRange {
x1: number; x1: number;