add blank OSCConnection
This commit is contained in:
@ -4,8 +4,6 @@ import { tryEvaluate } from "./Evaluator";
|
||||
import { MidiConnection } from "./IO/MidiConnection";
|
||||
// @ts-ignore
|
||||
import { webaudioOutput, samples } from '@strudel.cycles/webaudio';
|
||||
import { MiniLanguage } from "./Walker";
|
||||
import * as astring from 'astring';
|
||||
|
||||
|
||||
const sound = (value: any) => ({
|
||||
@ -946,10 +944,4 @@ export class UserAPI {
|
||||
sound = async (values: object) => {
|
||||
webaudioOutput(sound(values), 0.00)
|
||||
}
|
||||
|
||||
ast(code: string) {
|
||||
const ast = MiniLanguage.parse(code, { ecmaVersion: 2020 });
|
||||
console.log(astring.generate(ast))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import type { Editor } from './main';
|
||||
import type { File } from './AppSettings';
|
||||
import { parseUserCode } from './Walker';
|
||||
|
||||
const delay = (ms: number) => new Promise((_, reject) => setTimeout(() => reject(new Error('Operation took too long')), ms));
|
||||
|
||||
@ -15,7 +16,7 @@ const tryCatchWrapper = (application: Editor, code: string): Promise<boolean> =>
|
||||
*/
|
||||
return new Promise((resolve, _) => {
|
||||
try {
|
||||
Function(`with (this) {try{${code}} catch (e) {console.log(e)}};`).call(application.api);
|
||||
Function(`with (this) {try{${parseUserCode(code)}} catch (e) {console.log(e)}};`).call(application.api);
|
||||
resolve(true);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
|
||||
0
src/IO/OSCConnection.ts
Normal file
0
src/IO/OSCConnection.ts
Normal file
@ -14,17 +14,14 @@ function myPlugin(Parser: typeof acorn.Parser): any {
|
||||
|
||||
// Replace the Literal node with an ArrayExpression node
|
||||
return {
|
||||
type: 'SpreadElement',
|
||||
argument: {
|
||||
type: 'ArrayExpression',
|
||||
elements: transformed.map(value => ({
|
||||
type: 'Literal',
|
||||
value,
|
||||
raw: value.toString()
|
||||
}))
|
||||
},
|
||||
start: node.start,
|
||||
end: node.end
|
||||
type: 'Literal',
|
||||
value,
|
||||
raw: value.toString()
|
||||
})),
|
||||
start: node.start,
|
||||
end: node.end
|
||||
};
|
||||
}
|
||||
|
||||
@ -45,6 +42,13 @@ function myPlugin(Parser: typeof acorn.Parser): any {
|
||||
}
|
||||
});
|
||||
|
||||
matches?.forEach(match => {
|
||||
const parts = match.split('~');
|
||||
const begin = parseInt(parts[0])
|
||||
const end = parseInt(parts[1])
|
||||
values.push(Math.floor(Math.random() * (end) + begin))
|
||||
})
|
||||
|
||||
return values;
|
||||
}
|
||||
};
|
||||
@ -52,10 +56,13 @@ function myPlugin(Parser: typeof acorn.Parser): any {
|
||||
|
||||
export const MiniLanguage = acorn.Parser.extend(myPlugin);
|
||||
|
||||
export function parseUserCode(code: string): string {
|
||||
let constructor = MiniLanguage.parse(code, { ecmaVersion: 2020 });
|
||||
return astring.generate(constructor)
|
||||
}
|
||||
|
||||
// Sample code
|
||||
// const code = `
|
||||
// const a = '3!4 5'; // This should become const a = [...[3,3,3,3,5]];
|
||||
// `;
|
||||
// const code = `const a = '3!4 5'; // This should become const a = [...[3,3,3,3,5]];`;
|
||||
|
||||
// Parse the code
|
||||
// const ast = MiniLanguage.parse(code, { ecmaVersion: 2020 });
|
||||
|
||||
Reference in New Issue
Block a user