add blank OSCConnection
This commit is contained in:
@ -4,8 +4,6 @@ import { tryEvaluate } from "./Evaluator";
|
|||||||
import { MidiConnection } from "./IO/MidiConnection";
|
import { MidiConnection } from "./IO/MidiConnection";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { webaudioOutput, samples } from '@strudel.cycles/webaudio';
|
import { webaudioOutput, samples } from '@strudel.cycles/webaudio';
|
||||||
import { MiniLanguage } from "./Walker";
|
|
||||||
import * as astring from 'astring';
|
|
||||||
|
|
||||||
|
|
||||||
const sound = (value: any) => ({
|
const sound = (value: any) => ({
|
||||||
@ -946,10 +944,4 @@ export class UserAPI {
|
|||||||
sound = async (values: object) => {
|
sound = async (values: object) => {
|
||||||
webaudioOutput(sound(values), 0.00)
|
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 { Editor } from './main';
|
||||||
import type { File } from './AppSettings';
|
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));
|
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, _) => {
|
return new Promise((resolve, _) => {
|
||||||
try {
|
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);
|
resolve(true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(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
|
// Replace the Literal node with an ArrayExpression node
|
||||||
return {
|
return {
|
||||||
type: 'SpreadElement',
|
|
||||||
argument: {
|
|
||||||
type: 'ArrayExpression',
|
type: 'ArrayExpression',
|
||||||
elements: transformed.map(value => ({
|
elements: transformed.map(value => ({
|
||||||
type: 'Literal',
|
type: 'Literal',
|
||||||
value,
|
value,
|
||||||
raw: value.toString()
|
raw: value.toString()
|
||||||
}))
|
})),
|
||||||
},
|
start: node.start,
|
||||||
start: node.start,
|
end: node.end
|
||||||
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;
|
return values;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -52,10 +56,13 @@ function myPlugin(Parser: typeof acorn.Parser): any {
|
|||||||
|
|
||||||
export const MiniLanguage = acorn.Parser.extend(myPlugin);
|
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
|
// Sample code
|
||||||
// const code = `
|
// const code = `const a = '3!4 5'; // This should become const a = [...[3,3,3,3,5]];`;
|
||||||
// const a = '3!4 5'; // This should become const a = [...[3,3,3,3,5]];
|
|
||||||
// `;
|
|
||||||
|
|
||||||
// Parse the code
|
// Parse the code
|
||||||
// const ast = MiniLanguage.parse(code, { ecmaVersion: 2020 });
|
// const ast = MiniLanguage.parse(code, { ecmaVersion: 2020 });
|
||||||
|
|||||||
Reference in New Issue
Block a user