Testing zn method chaining
This commit is contained in:
@ -29,7 +29,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": "file:../zifferjs",
|
"zifferjs": "https://github.com/amiika/zifferjs.git",
|
||||||
"zzfx": "^1.2.0"
|
"zzfx": "^1.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
43
src/API.ts
43
src/API.ts
@ -3,7 +3,7 @@ import { scale } from './Scales';
|
|||||||
import { tryEvaluate } from "./Evaluator";
|
import { tryEvaluate } from "./Evaluator";
|
||||||
import { MidiConnection } from "./IO/MidiConnection";
|
import { MidiConnection } from "./IO/MidiConnection";
|
||||||
import { DrunkWalk } from './Utils/Drunk';
|
import { DrunkWalk } from './Utils/Drunk';
|
||||||
import { next, Pitch, Chord, Rest } from "zifferjs";
|
import { Pitch, Chord, Rest, Event, Start, cachedStart } from "zifferjs";
|
||||||
import {
|
import {
|
||||||
superdough, samples,
|
superdough, samples,
|
||||||
initAudioOnFirstClick,
|
initAudioOnFirstClick,
|
||||||
@ -176,25 +176,32 @@ export class UserAPI {
|
|||||||
this.MidiConnection.sendMidiNote(note, channel, velocity, duration)
|
this.MidiConnection.sendMidiNote(note, channel, velocity, duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
public zn(input: string, options: {[key: string]: string|number} = {}): Pitch|Chord|Rest {
|
public zn(input: string, options: {[key: string]: string|number} = {}): Event {
|
||||||
const node = next(input, options) as any;
|
let event = cachedStart(input, options);
|
||||||
const channel = (options.channel ? options.channel : 0) as number;
|
if(event instanceof Start) {
|
||||||
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) {
|
|
||||||
// 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 node;
|
return event.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
public sysex(data: Array<number>): void {
|
public sysex(data: Array<number>): void {
|
||||||
|
|||||||
@ -1158,8 +1158,9 @@ 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@file:../zifferjs":
|
"zifferjs@https://github.com/amiika/zifferjs.git":
|
||||||
version "0.0.0"
|
version "0.0.0"
|
||||||
|
resolved "https://github.com/amiika/zifferjs.git#374ee4edb0b07d9968b635f899f9f88d79ddaa07"
|
||||||
dependencies:
|
dependencies:
|
||||||
"@types/seedrandom" "^3.0.5"
|
"@types/seedrandom" "^3.0.5"
|
||||||
lru-cache "^10.0.0"
|
lru-cache "^10.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user