diff --git a/package.json b/package.json index a9a0b1c..e933d89 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "superdough": "^0.9.3", "tailwindcss": "^3.3.3", "tone": "^14.8.49", - "zifferjs": "file:../zifferjs", + "zifferjs": "https://github.com/amiika/zifferjs.git", "zzfx": "^1.2.0" } } diff --git a/src/API.ts b/src/API.ts index 3510cb6..3cca2e1 100644 --- a/src/API.ts +++ b/src/API.ts @@ -3,7 +3,7 @@ import { scale } from './Scales'; import { tryEvaluate } from "./Evaluator"; import { MidiConnection } from "./IO/MidiConnection"; import { DrunkWalk } from './Utils/Drunk'; -import { next, Pitch, Chord, Rest } from "zifferjs"; +import { Pitch, Chord, Rest, Event, Start, cachedStart } from "zifferjs"; import { superdough, samples, initAudioOnFirstClick, @@ -176,25 +176,32 @@ export class UserAPI { this.MidiConnection.sendMidiNote(note, channel, velocity, duration) } - public zn(input: string, options: {[key: string]: string|number} = {}): Pitch|Chord|Rest { - const node = next(input, options) as any; - const channel = (options.channel ? options.channel : 0) as number; - const velocity = (options.velocity ? options.velocity : 100) as number; - const sustain = (options.sustain ? options.sustain : 0.5) as number; - if(node instanceof Pitch) { - if(node.bend) this.MidiConnection.sendPitchBend(node.bend, channel); - this.MidiConnection.sendMidiNote(node.note!, channel, velocity, sustain); - if(node.bend) this.MidiConnection.sendPitchBend(8192, channel); - } else if(node instanceof Chord) { - node.pitches.forEach(pitch => { - if(pitch.bend) this.MidiConnection.sendPitchBend(pitch.bend, channel); - this.MidiConnection.sendMidiNote(pitch.note!, channel, velocity, sustain); - if(pitch.bend) this.MidiConnection.sendPitchBend(8192, channel); - }); - } else if(node instanceof Rest) { + public zn(input: string, options: {[key: string]: string|number} = {}): Event { + let event = cachedStart(input, options); + if(event instanceof Start) { // do nothing for now ... + } else { + let node = event; + if(node.modifiedEvent) node = node.modifiedEvent; + const channel = (options.channel ? options.channel : 0) as number; + const velocity = (options.velocity ? options.velocity : 100) as number; + const sustain = (options.sustain ? options.sustain : 0.5) as number; + if(node instanceof Pitch) { + if(node.bend) this.MidiConnection.sendPitchBend(node.bend, channel); + this.MidiConnection.sendMidiNote(node.note!, channel, velocity, sustain); + if(node.bend) this.MidiConnection.sendPitchBend(8192, channel); + } else if(node instanceof Chord) { + node.pitches.forEach((pitch: Pitch) => { + if(pitch.bend) this.MidiConnection.sendPitchBend(pitch.bend, channel); + this.MidiConnection.sendMidiNote(pitch.note!, channel, velocity, sustain); + if(pitch.bend) this.MidiConnection.sendPitchBend(8192, channel); + }); + } else if(node instanceof Rest) { + // do nothing for now ... + } + if(node.modifiedEvent) node.modifiedEvent = undefined; } - return node; + return event.next(); } public sysex(data: Array): void { diff --git a/yarn.lock b/yarn.lock index 2a03731..993b371 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1158,8 +1158,9 @@ yaml@^2.1.1: resolved "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz" integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ== -"zifferjs@file:../zifferjs": +"zifferjs@https://github.com/amiika/zifferjs.git": version "0.0.0" + resolved "https://github.com/amiika/zifferjs.git#374ee4edb0b07d9968b635f899f9f88d79ddaa07" dependencies: "@types/seedrandom" "^3.0.5" lru-cache "^10.0.0"