From 226e399f9fc074b033a0c0efdad07c4a30a2a81a Mon Sep 17 00:00:00 2001 From: Miika Alonen Date: Wed, 16 Aug 2023 00:58:17 +0300 Subject: [PATCH] Update zifferjs --- package.json | 2 +- src/API.ts | 50 ++++++++++++++++++++++++++------------------------ yarn.lock | 8 ++++---- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/package.json b/package.json index 2266cfd..52e2459 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.1", + "zifferjs": "^0.0.2", "zzfx": "^1.2.0" } } diff --git a/src/API.ts b/src/API.ts index 0d2fe2c..24d3d3c 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 { Pitch, Chord, Rest, Event, Start, cachedStart, pattern } from "zifferjs"; +import { Pitch, Chord, Rest, Event, cachedEvent} from "zifferjs"; import { superdough, samples, @@ -189,31 +189,33 @@ export class UserAPI { public zn(input: string, options: {[key: string]: string|number} = {}): Event { - const event = cachedStart(input, options); - if(event instanceof Start) { + let event = cachedEvent(input, options); + + // 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; + + 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 ... - } 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 event.next(); + + // Remove old modified event + if(event.modifiedEvent) event.modifiedEvent = undefined; + + return node.next(); } public sysex(data: Array): void { diff --git a/yarn.lock b/yarn.lock index d966794..f196faa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1153,10 +1153,10 @@ yaml@^2.1.1: resolved "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz" integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ== -zifferjs@^0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.1.tgz#9ddd0e56efb1652105fa11f9496fe61b228c8862" - integrity sha512-D7y79/RfHyMD5bWN0DD3VDWRk/XXuknvYBFuuZ77xe3heOiTZ6j+g3MS9AMewCDoTWIgWN79vPs2VYey89DdOQ== +zifferjs@^0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.2.tgz#17abcba0874da603908baefd00bee764300e5cb9" + integrity sha512-NQ9JxMDA5dBQF6kiTFJxDQKxpFn5qklDLu6ow/53V+E8RVEbpSsYcSBhcJ893u5Re4vSooJDJOcMsQwcF4GYww== dependencies: lru-cache "^10.0.0" seedrandom "^3.0.5"