This commit is contained in:
2023-08-16 11:18:10 +02:00
3 changed files with 31 additions and 28 deletions

View File

@ -30,7 +30,7 @@
"superdough": "^0.9.3", "superdough": "^0.9.3",
"tailwindcss": "^3.3.3", "tailwindcss": "^3.3.3",
"tone": "^14.8.49", "tone": "^14.8.49",
"zifferjs": "^0.0.1", "zifferjs": "^0.0.2",
"zzfx": "^1.2.0" "zzfx": "^1.2.0"
} }
} }

View File

@ -5,6 +5,7 @@ import { DrunkWalk } from "./Utils/Drunk";
import { LRUCache } from 'lru-cache'; import { LRUCache } from 'lru-cache';
import { scale } from "./Scales"; import { scale } from "./Scales";
import { Editor } from "./main"; import { Editor } from "./main";
import { Pitch, Chord, Rest, Event, cachedEvent} from "zifferjs";
import { import {
superdough, superdough,
samples, samples,
@ -192,31 +193,33 @@ export class UserAPI {
public zn(input: string, public zn(input: string,
options: {[key: string]: string|number} = {}): Event { options: {[key: string]: string|number} = {}): Event {
const event = cachedStart(input, options); let event = cachedEvent(input, options);
if(event instanceof Start) {
// 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 ... // 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<number>): void { public sysex(data: Array<number>): void {

View File

@ -1153,10 +1153,10 @@ yaml@^2.1.1:
resolved "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz" resolved "https://registry.npmjs.org/yaml/-/yaml-2.3.1.tgz"
integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ== integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==
zifferjs@^0.0.1: zifferjs@^0.0.2:
version "0.0.1" version "0.0.2"
resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.1.tgz#9ddd0e56efb1652105fa11f9496fe61b228c8862" resolved "https://registry.yarnpkg.com/zifferjs/-/zifferjs-0.0.2.tgz#17abcba0874da603908baefd00bee764300e5cb9"
integrity sha512-D7y79/RfHyMD5bWN0DD3VDWRk/XXuknvYBFuuZ77xe3heOiTZ6j+g3MS9AMewCDoTWIgWN79vPs2VYey89DdOQ== integrity sha512-NQ9JxMDA5dBQF6kiTFJxDQKxpFn5qklDLu6ow/53V+E8RVEbpSsYcSBhcJ893u5Re4vSooJDJOcMsQwcF4GYww==
dependencies: dependencies:
lru-cache "^10.0.0" lru-cache "^10.0.0"
seedrandom "^3.0.5" seedrandom "^3.0.5"