/** * Relabi controls * @module src/ui/Controls.jsx; */ import * as React from "react"; import { useState, useCallback, useRef } from "react"; import Slider from "rc-slider"; import TooltipSlider, { handleRender } from "./TooltipSlider.tsx"; import "rc-slider/assets/index.css"; const WAVE_SHAPE_NAMES = [ "sine", "triangle", "saw", "reverse_saw", "square", "noise", ]; export default function Controls({ relabi }) { const [paused, setPaused] = useState(false); /** * Handle updating a slider */ const onChange = useCallback( (type, index) => (value) => { if (type === "bound") { relabi.bounds[index].level = value; } if (type === "shape") { relabi.waves[index].shape = WAVE_SHAPE_NAMES[value]; } if (type === "frequency") { relabi.waves[index].frequency = Math.round(Math.exp(value) * 10) / 10; } if (type === "weight") { relabi.waves[index].weight = value; } if (type === "settings") { relabi.settings[index] = index === "speed" ? Math.exp(value) : value; } }, [relabi] ); /** * Handle pause/unpause */ const onPause = useCallback(() => { relabi.paused = !paused; setPaused(!paused); }, [relabi, paused]); if (!relabi) { return null; } return ( {relabi?.bounds.map((bound, index) => ( -value} defaultValue={bound.level} color={bound.color} reverse /> ))} {relabi?.waves.map((wave, index) => ( Math.exp(value).toFixed(1)} color={"#8a8"} /> ))} {relabi?.waves.map((wave, index) => ( WAVE_SHAPE_NAMES[value]} /> ))} {relabi?.waves.map((wave, index) => ( ))} Math.exp(value).toFixed(1)} color={"#a88"} /> ); } /** * UI Elements */ const ControlRow = ({ children }) => (
{children}
); const ControlBox = ({ children }) => (
{children}
); const SliderRow = ({ children }) => (
{children}
); const Label = ({ children }) => (
{children}
); const Button = ({ color, onClick, children }) => ( ); const ControlSlider = ({ type, index, min, max, step, reverse, defaultValue, color, onChange, tipFormatter, }) => (
value)} />
);