Skip to content

Commit

Permalink
Updates for trackers
Browse files Browse the repository at this point in the history
  • Loading branch information
dcyoung committed Oct 12, 2024
1 parent 59af85e commit 0393d17
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 46 deletions.
3 changes: 1 addition & 2 deletions app/src/components/canvas/AudioScope.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { CanvasBackground } from "@/components/canvas/common";
import { Canvas } from "@react-three/fiber";

import ModalVisual from "../visualizers/visualizerModal";

const AudioScopeCanvas = () => {
return (
<Canvas>
<CanvasBackground />
<color attach="background" args={["#010204"]} />;
<ModalVisual />
</Canvas>
);
Expand Down
1 change: 1 addition & 0 deletions app/src/components/controls/visualSettingsSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const VisualControlsComponent = () => {
export const VisualSettingsSheetContent = () => {
const mode = useMode();
const { colorBackground, paletteTrackEnergy } = useAppearance();
console.log(colorBackground, paletteTrackEnergy);
const palette = usePalette();
const { setAppearance } = useAppStateActions();
const { autoOrbitAfterSleepMs } = useCameraState();
Expand Down
68 changes: 31 additions & 37 deletions app/src/components/visualizers/visualizerModal.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@
import { useMemo } from "react";
import { APPLICATION_MODE } from "@/lib/applicationModes";
import { useMappers, useMode, useVisual } from "@/lib/appState";
import { type ICoordinateMapper } from "@/lib/mappers/coordinateMappers/common";

const DummyMapper: ICoordinateMapper = { map: () => 0, amplitude: 0 };
const useScalarTracker = () => {
const mode = useMode();
const { energyTracker } = useMappers();
switch (mode) {
case APPLICATION_MODE.AUDIO:
return energyTracker;
default:
return undefined;
}
};
const useCoordinateMapper = () => {
const useVisualParams = () => {
const mode = useMode();
const {
coordinateMapperWaveform,
coordinateMapperNoise,
coordinateMapperData,
coordinateMapperNoise,
coordinateMapperWaveform,
...rest
} = useMappers();
switch (mode) {
case APPLICATION_MODE.WAVE_FORM:
return coordinateMapperWaveform;
case APPLICATION_MODE.NOISE:
return coordinateMapperNoise;
case APPLICATION_MODE.AUDIO:
return coordinateMapperData;
case APPLICATION_MODE.AUDIO_SCOPE:
case APPLICATION_MODE.PARTICLE_NOISE:
return DummyMapper;
const coordinateMapper = useMemo(() => {
switch (mode) {
case APPLICATION_MODE.WAVE_FORM:
return coordinateMapperWaveform;
case APPLICATION_MODE.NOISE:
return coordinateMapperNoise;
case APPLICATION_MODE.AUDIO:
return coordinateMapperData;
case APPLICATION_MODE.AUDIO_SCOPE:
case APPLICATION_MODE.PARTICLE_NOISE:
return DummyMapper;
default:
return mode satisfies never;
}
}, [
mode,
coordinateMapperData,
coordinateMapperNoise,
coordinateMapperWaveform,
]);

default:
return mode satisfies never;
}
return {
coordinateMapper,
...rest,
};
};
const ModalVisual = () => {
const visual = useVisual();
const coordinateMapper = useCoordinateMapper();
const scalarTracker = useScalarTracker();
const { textureMapper, motionMapper } = useMappers();
return (
<visual.ReactiveComponent
coordinateMapper={coordinateMapper}
scalarTracker={scalarTracker ?? undefined}
textureMapper={textureMapper}
motionMapper={motionMapper}
/>
);
const visualParams = useVisualParams();
return <visual.ReactiveComponent {...visualParams} />;
};

export default ModalVisual;
18 changes: 12 additions & 6 deletions app/src/lib/appState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import { CoordinateMapper_WaveformSuperposition } from "./mappers/coordinateMapp
import { type IMotionMapper } from "./mappers/motionMappers/common";
import { MotionMapper_Noise } from "./mappers/motionMappers/curlNoise";
import { TextureMapper } from "./mappers/textureMappers/textureMapper";
import {
NoOpScalarTracker,
type IScalarTracker,
} from "./mappers/valueTracker/common";
import { EnergyTracker } from "./mappers/valueTracker/energyTracker";
import {
AVAILABLE_COLOR_PALETTES,
Expand All @@ -41,7 +45,7 @@ interface IMappersState {
coordinateMapperWaveform: CoordinateMapper_WaveformSuperposition;
coordinateMapperNoise: CoordinateMapper_Noise;
coordinateMapperData: CoordinateMapper_Data;
energyTracker: EnergyTracker | null;
energyTracker: IScalarTracker | null;
}
interface IAudioState {
source: TAudioSource;
Expand Down Expand Up @@ -168,17 +172,20 @@ const useAppState = create<IAppState>((set) => ({
set((state) => {
return {
mode: newMode,
// audio: {
// ...state.audio,
// sourceCounter: state.audio.sourceCounter + 1,
// },
...(![...state.visual.supportedApplicationModes].includes(newMode)
? {
visual: Object.values(VISUAL_REGISTRY).find((v) =>
[...v.supportedApplicationModes].includes(newMode),
),
}
: {}),
mappers: {
...state.mappers,
energyTracker:
newMode === APPLICATION_MODE.AUDIO
? new EnergyTracker(0)
: NoOpScalarTracker,
},
appearance: {
...state.appearance,
// Reset paletteTrackEnergy whenever the mode changes
Expand All @@ -187,7 +194,6 @@ const useAppState = create<IAppState>((set) => ({
...(newMode === APPLICATION_MODE.AUDIO_SCOPE
? {
palette: "rainbow",
colorBackground: false,
}
: {}),
},
Expand Down
8 changes: 7 additions & 1 deletion app/src/lib/mappers/valueTracker/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
* Tracks scalar values
*/
export interface IScalarTracker {
// set(value: number): void;
set(value: number): void;
get(): number;
}

export const NoOpScalarTracker: IScalarTracker = {
// eslint-disable-next-line @typescript-eslint/no-empty-function
set: () => {},
get: () => 0,
};

0 comments on commit 0393d17

Please sign in to comment.