mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-11 21:58:31 +00:00
now supporting tidal syntax directly
This commit is contained in:
parent
a00f00a7fe
commit
bc79986dd2
@ -24,6 +24,7 @@ synth.set({
|
||||
});
|
||||
|
||||
function App() {
|
||||
const [mode, setMode] = useState<string>('javascript');
|
||||
const [code, setCode] = useState<string>(tetrisHaskell);
|
||||
const [log, setLog] = useState('');
|
||||
const logBox = useRef<any>();
|
||||
@ -64,7 +65,17 @@ function App() {
|
||||
// parse pattern when code changes
|
||||
useEffect(() => {
|
||||
try {
|
||||
const _pattern = parse(code);
|
||||
let _pattern;
|
||||
try {
|
||||
_pattern = h(code);
|
||||
setMode('pegjs'); // haskell mode does not recognize quotes, pegjs looks ok by accident..
|
||||
// console.log('h _pattern', _pattern);
|
||||
} catch (err) {
|
||||
setMode('javascript');
|
||||
// code is not haskell like
|
||||
_pattern = parse(code);
|
||||
// console.log('not haskell..', _pattern);
|
||||
}
|
||||
setPattern(_pattern);
|
||||
// cycle.query(cycle.activeCycle()); // reschedule active cycle
|
||||
setError(undefined);
|
||||
@ -88,6 +99,11 @@ function App() {
|
||||
<div className={cx('h-full bg-slate-600', error ? 'focus:ring-red-500' : 'focus:ring-slate-800')}>
|
||||
<CodeMirror
|
||||
value={code}
|
||||
options={{
|
||||
mode,
|
||||
theme: 'material',
|
||||
lineNumbers: true,
|
||||
}}
|
||||
onChange={(_: any, __: any, value: any) => {
|
||||
setLog((log) => log + `${log ? '\n\n' : ''}✏️ edit\n${code}\n${value}`);
|
||||
setCode(value);
|
||||
@ -110,7 +126,13 @@ function App() {
|
||||
>
|
||||
{cycle.started ? 'pause' : 'play'}
|
||||
</button>
|
||||
<textarea className="grow bg-[#283237] border-0" value={log} readOnly ref={logBox} style={{ fontFamily: 'monospace' }} />
|
||||
<textarea
|
||||
className="grow bg-[#283237] border-0"
|
||||
value={log}
|
||||
readOnly
|
||||
ref={logBox}
|
||||
style={{ fontFamily: 'monospace' }}
|
||||
/>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { Controlled as CodeMirror2 } from 'react-codemirror2';
|
||||
import 'codemirror/mode/javascript/javascript.js';
|
||||
import 'codemirror/mode/pegjs/pegjs.js';
|
||||
import 'codemirror/theme/material.css';
|
||||
import 'codemirror/lib/codemirror.css';
|
||||
|
||||
|
||||
@ -96,6 +96,6 @@ export const mini = (...strings: string[]) => {
|
||||
// includes haskell style (raw krill parsing)
|
||||
export const h = (string: string) => {
|
||||
const ast = krill.parse(string);
|
||||
console.log('ast', ast);
|
||||
// console.log('ast', ast);
|
||||
return patternifyAST(ast);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user