Skip to content

Commit

Permalink
feat(dryads): Automatically add surrounding { } where required to scl…
Browse files Browse the repository at this point in the history
…ang SynthDef code

Allows minimal SynthDef definitions: `|freq| SinOsc.ar(freq)`
Long form:
`SynthDef("SinOsc", {|out, freq| Out.ar(out, SinOsc.ar(freq)) });`
  • Loading branch information
crucialfelix committed Dec 6, 2019
1 parent 029d67b commit 89314b6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/dryads/src/SCSynthDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ export default class SCSynthDef extends Dryad<Properties> {
* Returns a Promise for a SynthDef result object: name, bytes, synthDesc
*/
async compileSource(context: Context, sourceCode: string, pathName?: string): Promise<CompiledSynthDef> {
// add surrounding { } to any expressions that start with arg or |
const autoBraced = /^ *arg|\|/.test(sourceCode) ? `{ ${sourceCode} }` : sourceCode;
const wrappedCode = `{
var def = { ${sourceCode} }.value.asSynthDef;
var def = { ${autoBraced} }.value.asSynthDef;
(
name: def.name,
synthDesc: def.asSynthDesc.asJSON(),
Expand Down

0 comments on commit 89314b6

Please sign in to comment.