Update zifferjs

This commit is contained in:
2023-08-16 22:10:06 +03:00
parent d524a5290f
commit 89e82f7195
3 changed files with 32 additions and 30 deletions

View File

@ -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();
}
// =============================================================