From cd5ad3dc823eb8ec5a73bd80ea6c196ab578001c Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Wed, 24 Nov 2021 16:44:54 -0800 Subject: [PATCH] Stub out runtime choreography --- packages/webamp/demo/js/choreography.ts | 50 +++++++++++++++++++++++++ packages/webamp/demo/js/index.tsx | 3 ++ 2 files changed, 53 insertions(+) create mode 100644 packages/webamp/demo/js/choreography.ts diff --git a/packages/webamp/demo/js/choreography.ts b/packages/webamp/demo/js/choreography.ts new file mode 100644 index 00000000..fb1278be --- /dev/null +++ b/packages/webamp/demo/js/choreography.ts @@ -0,0 +1,50 @@ +import Webamp from "../../js/webampLazy"; +import { Slider } from "../../js/types"; +import { batch } from "react-redux"; + +const BANDS: Slider[] = [ + "preamp", + 60, + 170, + 310, + 600, + 1000, + 3000, + 6000, + 12000, + 14000, + 16000, +]; +export function choreograph(webamp: Webamp) { + let frameNum = 0; + function tick() { + frameNum += 1; + batch(() => { + for (const [i, band] of BANDS.entries()) { + const value = (Math.sin(i + frameNum / 60) + 1) * 50; + webamp.store.dispatch({ type: "SET_BAND_VALUE", band, value }); + } + }); + if (frameNum === 200 || frameNum === 400) { + document.getElementById("previous")?.classList.add("active"); + document.getElementById("playlist-add-menu")?.click(); + document + .querySelector("#playlist-add-menu ul") + .firstChild.classList.add("hover"); + } + if (frameNum === 400 || frameNum === 600) { + document.getElementById("playlist-remove-menu")?.click(); + } + if (frameNum === 600 || frameNum === 800) { + document.getElementById("playlist-selection-menu")?.click(); + } + if (frameNum === 800 || frameNum === 1000) { + document.getElementById("playlist-misc-menu")?.click(); + } + if (frameNum === 1000 || frameNum === 1200) { + document.getElementById("playlist-list-menu")?.click(); + } + window.requestAnimationFrame(tick); + } + window.requestAnimationFrame(tick); +} diff --git a/packages/webamp/demo/js/index.tsx b/packages/webamp/demo/js/index.tsx index cc293562..0f1f142d 100644 --- a/packages/webamp/demo/js/index.tsx +++ b/packages/webamp/demo/js/index.tsx @@ -17,6 +17,7 @@ import { import { disableMarquee, skinUrl as configSkinUrl } from "./config"; import DemoDesktop from "./DemoDesktop"; import enableMediaSession from "./mediaSession"; +// import { choreograph } from "./choreography"; declare global { const SENTRY_DSN: string; @@ -155,6 +156,8 @@ async function main() { document.getElementById("app") as HTMLDivElement ); + // choreograph(webamp); + if (!screenshot) { if (backgroundColor != null) { window.document.body.style.backgroundColor = backgroundColor;