mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-26 21:18:49 +00:00
add ui helpers
This commit is contained in:
parent
252b7037bd
commit
963cfe052a
@ -14,5 +14,17 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.CodeMirror-line > span {
|
.CodeMirror-line > span {
|
||||||
background-color: #2a323690;
|
background-color: #2a323699;
|
||||||
|
}
|
||||||
|
|
||||||
|
.darken::before {
|
||||||
|
content: ' ';
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
display: block;
|
||||||
|
background: black;
|
||||||
|
opacity: 0.5;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,6 +83,7 @@ function App() {
|
|||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex flex-col">
|
<div className="min-h-screen flex flex-col">
|
||||||
<header
|
<header
|
||||||
|
id="header"
|
||||||
className={cx(
|
className={cx(
|
||||||
'flex-none w-full h-14 px-2 flex border-b border-gray-200 justify-between z-[10]',
|
'flex-none w-full h-14 px-2 flex border-b border-gray-200 justify-between z-[10]',
|
||||||
uiHidden ? 'bg-transparent text-white' : 'bg-white'
|
uiHidden ? 'bg-transparent text-white' : 'bg-white'
|
||||||
@ -138,7 +139,7 @@ function App() {
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<section className="grow flex flex-col text-gray-100">
|
<section className="grow flex flex-col text-gray-100">
|
||||||
<div className="grow relative">
|
<div className="grow relative" id="code">
|
||||||
<div
|
<div
|
||||||
className={cx(
|
className={cx(
|
||||||
'h-full transition-opacity',
|
'h-full transition-opacity',
|
||||||
|
|||||||
@ -36,7 +36,7 @@ export const markEvent = (editor) => (time, event) => {
|
|||||||
{ line: start.line - 1, ch: start.column },
|
{ line: start.line - 1, ch: start.column },
|
||||||
{ line: end.line - 1, ch: end.column },
|
{ line: end.line - 1, ch: end.column },
|
||||||
//{ css: 'background-color: #FFCA28; color: black' } // background-color is now used by parent marking
|
//{ css: 'background-color: #FFCA28; color: black' } // background-color is now used by parent marking
|
||||||
{ css: 'outline: 1px solid #FFCA28; box-sizing:border-box' }
|
{ css: 'outline: 2px solid #FFCA28; box-sizing:border-box' }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
//Tone.Transport.schedule(() => { // problem: this can be cleared by scheduler...
|
//Tone.Transport.schedule(() => { // problem: this can be cleared by scheduler...
|
||||||
@ -51,7 +51,7 @@ export const markParens = (editor, data) => {
|
|||||||
const v = editor.getDoc().getValue();
|
const v = editor.getDoc().getValue();
|
||||||
const marked = getCurrentParenArea(v, data);
|
const marked = getCurrentParenArea(v, data);
|
||||||
parenMark?.clear();
|
parenMark?.clear();
|
||||||
parenMark = editor.getDoc().markText(...marked, { css: 'background-color: #00000020' }); //
|
parenMark = editor.getDoc().markText(...marked, { css: 'background-color: #0000dd20' }); //
|
||||||
};
|
};
|
||||||
|
|
||||||
// returns { line, ch } from absolute character offset
|
// returns { line, ch } from absolute character offset
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import './tune.mjs';
|
|||||||
import './tune.mjs';
|
import './tune.mjs';
|
||||||
import './pianoroll.mjs';
|
import './pianoroll.mjs';
|
||||||
import './draw.mjs';
|
import './draw.mjs';
|
||||||
|
import * as uiHelpers from './ui.mjs';
|
||||||
import * as drawHelpers from './draw.mjs';
|
import * as drawHelpers from './draw.mjs';
|
||||||
import gist from './gist.js';
|
import gist from './gist.js';
|
||||||
import shapeshifter from './shapeshifter';
|
import shapeshifter from './shapeshifter';
|
||||||
@ -35,7 +36,7 @@ hackLiteral(String, ['mini', 'm'], bootstrapped.mini); // comment out this line
|
|||||||
hackLiteral(String, ['pure', 'p'], bootstrapped.pure); // comment out this line if you panic
|
hackLiteral(String, ['pure', 'p'], bootstrapped.pure); // comment out this line if you panic
|
||||||
|
|
||||||
// this will add everything to global scope, which is accessed by eval
|
// this will add everything to global scope, which is accessed by eval
|
||||||
Object.assign(globalThis, bootstrapped, Tone, toneHelpers, voicingHelpers, drawHelpers, { gist });
|
Object.assign(globalThis, bootstrapped, Tone, toneHelpers, voicingHelpers, drawHelpers, uiHelpers, { gist });
|
||||||
|
|
||||||
export const evaluate: any = async (code: string) => {
|
export const evaluate: any = async (code: string) => {
|
||||||
const shapeshifted = shapeshifter(code); // transform syntactically correct js code to semantically usable code
|
const shapeshifted = shapeshifter(code); // transform syntactically correct js code to semantically usable code
|
||||||
|
|||||||
42
repl/src/ui.mjs
Normal file
42
repl/src/ui.mjs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import * as Tone from 'tone';
|
||||||
|
|
||||||
|
export const hideHeader = () => {
|
||||||
|
document.getElementById('header').style = 'display:none';
|
||||||
|
};
|
||||||
|
|
||||||
|
function frame(callback) {
|
||||||
|
if (window.strudelAnimation) {
|
||||||
|
cancelAnimationFrame(window.strudelAnimation);
|
||||||
|
}
|
||||||
|
const animate = (animationTime) => {
|
||||||
|
const toneTime = Tone.getTransport().seconds;
|
||||||
|
callback(animationTime, toneTime);
|
||||||
|
window.strudelAnimation = requestAnimationFrame(animate);
|
||||||
|
};
|
||||||
|
requestAnimationFrame(animate);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const backgroundImage = function (src, animateOptions) {
|
||||||
|
const container = document.getElementById('code');
|
||||||
|
const bg = 'background-image:url(' + src + ');background-size:contain;';
|
||||||
|
container.style = bg;
|
||||||
|
const { className: initialClassName } = container;
|
||||||
|
const handleOption = (option, value) => {
|
||||||
|
({
|
||||||
|
style: () => (container.style = bg + ';' + value),
|
||||||
|
className: () => (container.className = value + ' ' + initialClassName),
|
||||||
|
}[option]());
|
||||||
|
};
|
||||||
|
const funcOptions = Object.entries(animateOptions).filter(([_, v]) => typeof v === 'function');
|
||||||
|
const stringOptions = Object.entries(animateOptions).filter(([_, v]) => typeof v === 'string');
|
||||||
|
stringOptions.forEach(([option, value]) => handleOption(option, value));
|
||||||
|
|
||||||
|
if (funcOptions.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
frame((_, t) =>
|
||||||
|
funcOptions.forEach(([option, value]) => {
|
||||||
|
handleOption(option, value(t));
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user