diff --git a/package.json b/package.json index 059587d..85e8955 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "superdough": "^0.9.3", "tailwindcss": "^3.3.3", "tone": "^14.8.49", - "zifferjs": "^0.0.5", + "zifferjs": "^0.0.6", "zzfx": "^1.2.0" } } diff --git a/src/API.ts b/src/API.ts index c61d084..9c27b21 100644 --- a/src/API.ts +++ b/src/API.ts @@ -1,4 +1,4 @@ -import { Pitch, Chord, Rest, Event, cachedEvent } from "zifferjs"; +import { Pitch, Chord, Rest, Event, cachedPattern } from "zifferjs"; import { MidiConnection } from "./IO/MidiConnection"; import { tryEvaluate } from "./Evaluator"; import { DrunkWalk } from "./Utils/Drunk"; @@ -248,33 +248,35 @@ export class UserAPI { public zn(input: string, options: {[key: string]: string|number} = {}): Event { - let event = cachedEvent(input, options); + const pattern = cachedPattern(input, options); - // Check if event is modified - const node = event.modifiedEvent ? event.modifiedEvent : event; + if(pattern.hasStarted()) { + const event = pattern.peek(); + // Check if event is modified + const node = event.modifiedEvent ? event.modifiedEvent : event; + + 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; - 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 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 ... + } + + // Remove old modified event + if(event.modifiedEvent) event.modifiedEvent = undefined; } - - // Remove old modified event - if(event.modifiedEvent) event.modifiedEvent = undefined; - - return node.next(); + return pattern.next(); } // ============================================================= diff --git a/yarn.lock b/yarn.lock index eac6f08..3c6b921 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1148,10 +1148,10 @@ yaml@^2.1.1: resolved "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz" integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ== -zifferjs@^0.0.5: - version "0.0.5" - resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.5.tgz#b641e6d960e1b24389feacc0d975262af63cb75e" - integrity sha512-8IfsiiWigHLh1h7SaBtXe0Cig8bbvCR6mI4P/0n3j/oedY8WQcu5gj+v1q+VcQW0D2zfTvGGKrWZdqCjXrKRfw== +zifferjs@^0.0.6: + version "0.0.6" + resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.6.tgz#7adfaa6a2ce6bdd496289dd0454f1767e6e5244e" + integrity sha512-fruobVQUaoko2d99euiGlvkJZH4mbuekJxUKiOt20vuLHzEybaLzWy9OuOryPodCatWCY5fcs40lB86ST5fWbg== dependencies: lru-cache "^10.0.0"