Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mercury): Do not trigger empty error after evaluating #273

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions packages/web/src/lib/mercury-wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

import { Mercury } from "mercury-engine";

// global variable m for the main output sound from Mercury
declare global {
interface Window {
m : number;
m: number;
}
}

Expand Down Expand Up @@ -33,11 +32,13 @@ export class MercuryWrapper {
}

async initialize() {
if (this.initialized) { return; }
if (this.initialized) {
return;
}

// set initialized to true only when samples are loaded
this._repl = new Mercury({
onload: () => {
onload: () => {
this._onWarning(`Ready!`);
// console.log('Mercury loaded');
this.initialized = true;
Expand All @@ -47,31 +48,32 @@ export class MercuryWrapper {
// initialize the meter
this._repl.addMeter();
// update the value every 16ms for 60fps
this._meter = setInterval(() => window.m = this._repl.getMeter(), 16);
this._meter = setInterval(() => (window.m = this._repl.getMeter()), 16);
},
onmidi: () => {
console.log("MIDI devices ready");
},
onmidi: () => { console.log('MIDI devices ready') }
});
}

async tryEval(code: string) {
// store the code for retrying evaluation
this._code = code;

// if (!this.initialized) await this.initialize();
if (!this.initialized){
if (!this.initialized) {
this._onWarning(`Engine still loading`);
this.initialize();
} else {
try {
let parse = this._repl.code(code);
this._onError('');


let prints = parse.parseTree.print;
if (prints.length > 0){
if (prints.length > 0) {
// print prints from the code if there are any
this._onWarning(`${prints}`);
}
if (parse.errors.length > 0){
if (parse.errors.length > 0) {
console.log(parse.errors);
// print the first error that needs fixing
this._onError(`${parse.errors}`);
Expand Down
Loading