adding new important method
This commit is contained in:
@ -645,12 +645,12 @@ export class UserAPI {
|
|||||||
return this.app.clock.time_position.beat
|
return this.app.clock.time_position.beat
|
||||||
}
|
}
|
||||||
|
|
||||||
get t_beat(): number {
|
get ebeat(): number {
|
||||||
/**
|
/**
|
||||||
* Returns the current beat number since the origin of time
|
* Returns the current beat number since the origin of time
|
||||||
* TODO: fix! Why is this not working?
|
* TODO: fix! Why is this not working?
|
||||||
*/
|
*/
|
||||||
return Math.floor(this.app.clock.tick / this.app.clock.ppqn)
|
return this.app.clock.beats_since_origin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -47,7 +47,7 @@ export class Clock {
|
|||||||
this.time_position = { bar: 0, beat: 0, pulse: 0 }
|
this.time_position = { bar: 0, beat: 0, pulse: 0 }
|
||||||
this.bpm = 120;
|
this.bpm = 120;
|
||||||
this.time_signature = [4, 4];
|
this.time_signature = [4, 4];
|
||||||
this.ppqn = 48*2;
|
this.ppqn = 48;
|
||||||
ctx.audioWorklet.addModule(TransportProcessor).then((e) => {
|
ctx.audioWorklet.addModule(TransportProcessor).then((e) => {
|
||||||
this.transportNode = new TransportNode(ctx, {}, this.app);
|
this.transportNode = new TransportNode(ctx, {}, this.app);
|
||||||
this.transportNode.connect(ctx.destination);
|
this.transportNode.connect(ctx.destination);
|
||||||
@ -65,6 +65,10 @@ export class Clock {
|
|||||||
return this.time_signature[0];
|
return this.time_signature[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get beats_since_origin(): number {
|
||||||
|
return (this.time_position.bar - 1) * this.beats_per_bar + this.time_position.beat;
|
||||||
|
}
|
||||||
|
|
||||||
get pulse_duration(): number {
|
get pulse_duration(): number {
|
||||||
/**
|
/**
|
||||||
* Returns the duration of a pulse in seconds.
|
* Returns the duration of a pulse in seconds.
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
import type { Editor } from './main';
|
import type { Editor } from './main';
|
||||||
import type { File } from './AppSettings';
|
import type { File } from './AppSettings';
|
||||||
|
|
||||||
|
function codeInterceptor(code: string) {
|
||||||
|
return code.replace(/->/g, "&&")
|
||||||
|
}
|
||||||
|
|
||||||
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));
|
||||||
|
|
||||||
const tryCatchWrapper = (application: Editor, code: string): Promise<boolean> => {
|
const tryCatchWrapper = (application: Editor, code: string): Promise<boolean> => {
|
||||||
@ -15,7 +19,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{${codeInterceptor(code)}} catch (e) {console.log(e)}};`).call(application.api);
|
||||||
resolve(true);
|
resolve(true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@ -43,7 +47,7 @@ export const tryEvaluate = async (
|
|||||||
code.evaluations!++;
|
code.evaluations!++;
|
||||||
const isCodeValid = await Promise.race([tryCatchWrapper(
|
const isCodeValid = await Promise.race([tryCatchWrapper(
|
||||||
application,
|
application,
|
||||||
`let i = ${code.evaluations};` + code.candidate,
|
`let i = ${code.evaluations};` + codeInterceptor(code.candidate as string),
|
||||||
), delay(timeout)]);
|
), delay(timeout)]);
|
||||||
|
|
||||||
if (isCodeValid) {
|
if (isCodeValid) {
|
||||||
@ -66,7 +70,7 @@ export const evaluate = async (application: Editor, code: File, timeout = 1000):
|
|||||||
* @returns A promise that resolves to void
|
* @returns A promise that resolves to void
|
||||||
*/
|
*/
|
||||||
try {
|
try {
|
||||||
await Promise.race([tryCatchWrapper(application, code.committed as string), delay(timeout)]);
|
await Promise.race([tryCatchWrapper(application, codeInterceptor(code.committed as string)), delay(timeout)]);
|
||||||
if (code.evaluations)
|
if (code.evaluations)
|
||||||
code.evaluations++;
|
code.evaluations++;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user