diff --git a/package-lock.json b/package-lock.json
index 7aceb9e2..1cca99d9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -12545,8 +12545,9 @@
"dependencies": {
"@codemirror/lang-javascript": "^6.1.1",
"@strudel.cycles/core": "^0.3.2",
- "@strudel.cycles/eval": "^0.3.2",
"@strudel.cycles/tone": "^0.3.3",
+ "@strudel.cycles/transpiler": "^0.3.2",
+ "@strudel.cycles/webaudio": "^0.3.3",
"@uiw/codemirror-themes": "^4.12.4",
"@uiw/react-codemirror": "^4.12.4",
"react-hook-inview": "^4.5.0"
@@ -14463,8 +14464,9 @@
"requires": {
"@codemirror/lang-javascript": "^6.1.1",
"@strudel.cycles/core": "^0.3.2",
- "@strudel.cycles/eval": "^0.3.2",
"@strudel.cycles/tone": "^0.3.3",
+ "@strudel.cycles/transpiler": "^0.3.2",
+ "@strudel.cycles/webaudio": "^0.3.3",
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.2",
"@uiw/codemirror-themes": "^4.12.4",
@@ -20343,8 +20345,9 @@
"requires": {
"@codemirror/lang-javascript": "^6.1.1",
"@strudel.cycles/core": "^0.3.2",
- "@strudel.cycles/eval": "^0.3.2",
"@strudel.cycles/tone": "^0.3.3",
+ "@strudel.cycles/transpiler": "^0.3.2",
+ "@strudel.cycles/webaudio": "^0.3.3",
"@types/react": "^17.0.2",
"@types/react-dom": "^17.0.2",
"@uiw/codemirror-themes": "^4.12.4",
diff --git a/packages/core/cyclist.mjs b/packages/core/cyclist.mjs
index 9c4b91fb..4112e1c9 100644
--- a/packages/core/cyclist.mjs
+++ b/packages/core/cyclist.mjs
@@ -46,8 +46,8 @@ export class Cyclist {
interval, // duration of each cycle
);
}
- getPhase(latencyCompensation = true) {
- return this.phase - (latencyCompensation ? this.latency : 0);
+ getPhase() {
+ return this.getTime() - this.origin;
}
setStarted(v) {
this.started = v;
diff --git a/packages/tone/draw.mjs b/packages/core/draw.mjs
similarity index 95%
rename from packages/tone/draw.mjs
rename to packages/core/draw.mjs
index 58bc4399..5ff8a49a 100644
--- a/packages/tone/draw.mjs
+++ b/packages/core/draw.mjs
@@ -4,8 +4,7 @@ Copyright (C) 2022 Strudel contributors - see
=I&&t(a,i,c),a{A(),g(),v=setInterval(g,u*1e3)},A=()=>v!==void 0&&clearInterval(v);return{setDuration:D,start:m,stop:()=>{c=0,a=0,A()},pause:()=>A(),duration:i,getPhase:()=>a}}const xi="strudel.log";function Ne(e,t,i={}){console.log(`%c${e}`,"background-color: black;color:white;border-radius:15px"),typeof CustomEvent<"u"&&document.dispatchEvent(new CustomEvent(xi,{detail:{message:e,type:t,data:i}}))}Ne.key=xi;class Gr{worker;pattern;started=!1;cps=1;getTime;phase=0;constructor({interval:t,onTrigger:i,onToggle:u,onError:n,getTime:c,latency:a=.1}){this.getTime=c,this.onToggle=u,this.latency=a;const f=p=>Math.round(p*1e3)/1e3;this.clock=Wr(c,(p,D,g)=>{g===0&&(this.origin=p);const v=f(p-this.origin);this.phase=v-a;const m=f(v+D),A=c();try{this.pattern.queryArc(v,m).forEach(C=>{if(C.part.begin.equals(C.whole.begin)){const x=C.whole.begin+this.origin-A+a,I=C.duration*1;i?.(C,x,I)}})}catch(E){Ne(`[cyclist] error: ${E.message}`),n?.(E)}},t)}getPhase(t=!0){return this.phase-(t?this.latency:0)}setStarted(t){this.started=t,this.onToggle?.(t)}start(){if(!this.pattern)throw new Error("Scheduler: no pattern set! call .setPattern first.");Ne("[cyclist] start"),this.clock.start(),this.setStarted(!0)}pause(){Ne("[cyclist] pause"),this.clock.pause(),this.setStarted(!1)}stop(){Ne("[cyclist] stop"),this.clock.stop(),this.setStarted(!1)}setPattern(t,i=!1){this.pattern=t,i&&!this.started&&this.start()}setCps(t=1){this.cps=t}log(t,i,u){const n=u.filter(c=>c.hasOnset());console.log(`${t.toFixed(4)} - ${i.toFixed(4)} ${Array(n.length).fill("I").join("")}`)}}const{isPattern:zr,Pattern:Hr}=Ir;let Pt=!1;const Kr=async(...e)=>{Pt&&console.warn("evalScope was called more than once."),Pt=!0;const t=await Promise.allSettled(e),i=t.filter(u=>u.status==="fulfilled").map(u=>u.value);t.forEach((u,n)=>{u.status==="rejected"&&console.warn(`evalScope: module with index ${n} could not be loaded:`,u.reason)}),Object.assign(globalThis,...i,Hr.prototype.bootstrap())};function Qr(e,t={}){const{wrapExpression:i=!0,wrapAsync:u=!0}=t;i&&(e=`{${e}}`),u&&(e=`(async ()=>${e})()`);const n=`"use strict";return (${e})`;return Function(n)()}const Yr=async(e,t)=>{Pt||await Kr(),t&&(e=t(e));let u=await Qr(e,{wrapExpression:!!t});if(!zr(u)){console.log("evaluated",u);const n=`got "${typeof u}" instead of pattern`;throw new Error(n+(typeof u=="function"?", did you forget to call a function?":"."))}return{mode:"javascript",pattern:u}};function Xr({interval:e,defaultOutput:t,onSchedulerError:i,onEvalError:u,beforeEval:n,afterEval:c,getTime:a,transpiler:f,onToggle:p}){const D=new Gr({interval:e,onTrigger:async(E,C,x)=>{try{(!E.context.onTrigger||!E.context.dominantTrigger)&&await t(E,C,x),E.context.onTrigger&&await E.context.onTrigger(a()+C,E,a(),1)}catch(I){Ne(`[cyclist] error: ${I.message}`,"error")}},onError:i,getTime:a,onToggle:p});return{scheduler:D,evaluate:async(E,C=!0)=>{if(!E)throw new Error("no code to evaluate");try{n({code:E});const{pattern:x}=await Yr(E,f);return Ne("[eval] code updated"),D.setPattern(x,C),c({code:E,pattern:x}),x}catch(x){Ne(`[eval] error: ${x.message}`,"error"),u?.(x)}},start:()=>D.start(),stop:()=>D.stop(),pause:()=>D.pause()}}var $r=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},yi={},bi={};(function(e){(function t(i){var u,n,c,a,f,p;function D(F){var S={},B,w;for(B in F)F.hasOwnProperty(B)&&(w=F[B],typeof w=="object"&&w!==null?S[B]=D(w):S[B]=w);return S}function g(F,S){var B,w,W,N;for(w=F.length,W=0;w;)B=w>>>1,N=W+B,S(F[N])?w=B:(W=N+1,w-=B+1);return W}u={AssignmentExpression:"AssignmentExpression",AssignmentPattern:"AssignmentPattern",ArrayExpression:"ArrayExpression",ArrayPattern:"ArrayPattern",ArrowFunctionExpression:"ArrowFunctionExpression",AwaitExpression:"AwaitExpression",BlockStatement:"BlockStatement",BinaryExpression:"BinaryExpression",BreakStatement:"BreakStatement",CallExpression:"CallExpression",CatchClause:"CatchClause",ChainExpression:"ChainExpression",ClassBody:"ClassBody",ClassDeclaration:"ClassDeclaration",ClassExpression:"ClassExpression",ComprehensionBlock:"ComprehensionBlock",ComprehensionExpression:"ComprehensionExpression",ConditionalExpression:"ConditionalExpression",ContinueStatement:"ContinueStatement",DebuggerStatement:"DebuggerStatement",DirectiveStatement:"DirectiveStatement",DoWhileStatement:"DoWhileStatement",EmptyStatement:"EmptyStatement",ExportAllDeclaration:"ExportAllDeclaration",ExportDefaultDeclaration:"ExportDefaultDeclaration",ExportNamedDeclaration:"ExportNamedDeclaration",ExportSpecifier:"ExportSpecifier",ExpressionStatement:"ExpressionStatement",ForStatement:"ForStatement",ForInStatement:"ForInStatement",ForOfStatement:"ForOfStatement",FunctionDeclaration:"FunctionDeclaration",FunctionExpression:"FunctionExpression",GeneratorExpression:"GeneratorExpression",Identifier:"Identifier",IfStatement:"IfStatement",ImportExpression:"ImportExpression",ImportDeclaration:"ImportDeclaration",ImportDefaultSpecifier:"ImportDefaultSpecifier",ImportNamespaceSpecifier:"ImportNamespaceSpecifier",ImportSpecifier:"ImportSpecifier",Literal:"Literal",LabeledStatement:"LabeledStatement",LogicalExpression:"LogicalExpression",MemberExpression:"MemberExpression",MetaProperty:"MetaProperty",MethodDefinition:"MethodDefinition",ModuleSpecifier:"ModuleSpecifier",NewExpression:"NewExpression",ObjectExpression:"ObjectExpression",ObjectPattern:"ObjectPattern",PrivateIdentifier:"PrivateIdentifier",Program:"Program",Property:"Property",PropertyDefinition:"PropertyDefinition",RestElement:"RestElement",ReturnStatement:"ReturnStatement",SequenceExpression:"SequenceExpression",SpreadElement:"SpreadElement",Super:"Super",SwitchStatement:"SwitchStatement",SwitchCase:"SwitchCase",TaggedTemplateExpression:"TaggedTemplateExpression",TemplateElement:"TemplateElement",TemplateLiteral:"TemplateLiteral",ThisExpression:"ThisExpression",ThrowStatement:"ThrowStatement",TryStatement:"TryStatement",UnaryExpression:"UnaryExpression",UpdateExpression:"UpdateExpression",VariableDeclaration:"VariableDeclaration",VariableDeclarator:"VariableDeclarator",WhileStatement:"WhileStatement",WithStatement:"WithStatement",YieldExpression:"YieldExpression"},c={AssignmentExpression:["left","right"],AssignmentPattern:["left","right"],ArrayExpression:["elements"],ArrayPattern:["elements"],ArrowFunctionExpression:["params","body"],AwaitExpression:["argument"],BlockStatement:["body"],BinaryExpression:["left","right"],BreakStatement:["label"],CallExpression:["callee","arguments"],CatchClause:["param","body"],ChainExpression:["expression"],ClassBody:["body"],ClassDeclaration:["id","superClass","body"],ClassExpression:["id","superClass","body"],ComprehensionBlock:["left","right"],ComprehensionExpression:["blocks","filter","body"],ConditionalExpression:["test","consequent","alternate"],ContinueStatement:["label"],DebuggerStatement:[],DirectiveStatement:[],DoWhileStatement:["body","test"],EmptyStatement:[],ExportAllDeclaration:["source"],ExportDefaultDeclaration:["declaration"],ExportNamedDeclaration:["declaration","specifiers","source"],ExportSpecifier:["exported","local"],ExpressionStatement:["expression"],ForStatement:["init","test","update","body"],ForInStatement:["left","right","body"],ForOfStatement:["left","right","body"],FunctionDeclaration:["id","params","body"],FunctionExpression:["id","params","body"],GeneratorExpression:["blocks","filter","body"],Identifier:[],IfStatement:["test","consequent","alternate"],ImportExpression:["source"],ImportDeclaration:["specifiers","source"],ImportDefaultSpecifier:["local"],ImportNamespaceSpecifier:["local"],ImportSpecifier:["imported","local"],Literal:[],LabeledStatement:["label","body"],LogicalExpression:["left","right"],MemberExpression:["object","property"],MetaProperty:["meta","property"],MethodDefinition:["key","value"],ModuleSpecifier:[],NewExpression:["callee","arguments"],ObjectExpression:["properties"],ObjectPattern:["properties"],PrivateIdentifier:[],Program:["body"],Property:["key","value"],PropertyDefinition:["key","value"],RestElement:["argument"],ReturnStatement:["argument"],SequenceExpression:["expressions"],SpreadElement:["argument"],Super:[],SwitchStatement:["discriminant","cases"],SwitchCase:["test","consequent"],TaggedTemplateExpression:["tag","quasi"],TemplateElement:[],TemplateLiteral:["quasis","expressions"],ThisExpression:[],ThrowStatement:["argument"],TryStatement:["block","handler","finalizer"],UnaryExpression:["argument"],UpdateExpression:["argument"],VariableDeclaration:["declarations"],VariableDeclarator:["id","init"],WhileStatement:["test","body"],WithStatement:["object","body"],YieldExpression:["argument"]},a={},f={},p={},n={Break:a,Skip:f,Remove:p};function v(F,S){this.parent=F,this.key=S}v.prototype.replace=function(S){this.parent[this.key]=S},v.prototype.remove=function(){return Array.isArray(this.parent)?(this.parent.splice(this.key,1),!0):(this.replace(null),!1)};function m(F,S,B,w){this.node=F,this.path=S,this.wrap=B,this.ref=w}function A(){}A.prototype.path=function(){var S,B,w,W,N,G;function q(R,j){if(Array.isArray(j))for(w=0,W=j.length;w126))){o+=gr(d,r.charCodeAt(s+1));continue}o+=String.fromCharCode(d)}if(k=!(m==="double"||m==="auto"&&_=0&&!a.code.isLineTerminator(r.charCodeAt(o));--o);return r.length-1-o}function Fr(r,o){var s,l,d,b,_,k,L,K;for(s=r.split(/\r\n|[\r\n]/),k=Number.MAX_VALUE,l=1,d=s.length;l