Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@blibliki/engine

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blibliki/engine - npm Package Compare versions

Comparing version 0.1.11 to 0.1.12

5

build/Engine.d.ts

@@ -83,2 +83,7 @@ import MidiDeviceManager from "./MidiDeviceManager";

findById(id: string): AudioModule;
get isStarted(): boolean;
start(): void;
stop(): void;
get bpm(): number;
set bpm(value: number);
private applyRoutesRequired;

@@ -85,0 +90,0 @@ private moduleRouteIds;

32

build/Engine.js

@@ -1,2 +0,2 @@

import { Context, setContext } from "tone";
import { Context, now, setContext } from "tone";
import MidiDeviceManager from "./MidiDeviceManager";

@@ -37,3 +37,4 @@ import MidiEvent from "./MidiEvent";

registerModule(name, type, props = {}) {
const audioModule = createModule(name, type, props);
const audioModule = createModule(name, type, {});
audioModule.props = props;
this.modules[audioModule.id] = audioModule;

@@ -107,2 +108,29 @@ applyRoutes(Object.values(this.routes));

}
get isStarted() {
return this.context.transport.state === "started";
}
start() {
const startTime = now();
Object.values(this.modules).forEach((audioModule) => {
const am = audioModule;
if (!am.start)
return;
am.start(startTime);
});
}
stop() {
const startTime = now();
Object.values(this.modules).forEach((audioModule) => {
const am = audioModule;
if (!am.stop)
return;
am.stop(startTime);
});
}
get bpm() {
return this.context.transport.bpm.value;
}
set bpm(value) {
this.context.transport.bpm.value = value;
}
applyRoutesRequired(audioModule, props) {

@@ -109,0 +137,0 @@ if (!props.polyNumber)

2

build/Module/Base.d.ts

@@ -14,3 +14,2 @@ import { InputNode } from "tone";

triggerRelease: Function;
triggerAttackRelease: Function;
}

@@ -52,3 +51,2 @@ export interface Voicable {

triggerRelease(note: Note, triggeredAt: number): void;
triggerAttackRelease(note: Note, triggeredAt: number): void;
midiTriggered: (midiEvent: MidiEvent, noteIndex?: number) => void;

@@ -55,0 +53,0 @@ private triggerer;

@@ -74,12 +74,15 @@ import { v4 as uuidv4 } from "uuid";

}
triggerAttackRelease(note, triggeredAt) {
throw Error("triggerAttackRelease not implemented");
}
midiTriggered = (midiEvent, noteIndex) => {
const { notes, triggeredAt } = midiEvent;
switch (midiEvent.type) {
case "noteOn":
this.triggerer(this.triggerAttack, midiEvent, noteIndex);
const { duration } = notes[0];
this.triggerer(this.triggerAttack, notes, triggeredAt, noteIndex);
if (duration) {
const releaseTriggeredAt = triggeredAt + this.internalModule.toSeconds(duration);
this.triggerer(this.triggerRelease, notes, releaseTriggeredAt, noteIndex);
}
break;
case "noteOff":
this.triggerer(this.triggerRelease, midiEvent, noteIndex);
this.triggerer(this.triggerRelease, notes, triggeredAt, noteIndex);
break;

@@ -90,4 +93,3 @@ default:

};
triggerer(trigger, midiEvent, noteIndex) {
const { notes, triggeredAt } = midiEvent;
triggerer(trigger, notes, triggeredAt, noteIndex) {
if (noteIndex !== undefined && this.voiceNo !== undefined) {

@@ -94,0 +96,0 @@ trigger(notes[noteIndex], triggeredAt);

@@ -32,3 +32,2 @@ import { Envelope as Env } from "tone";

triggerAttack: (note: Note, triggeredAt: number) => void;
triggerAttackRelease: (note: Note, triggeredAt: number) => void;
triggerRelease: (note: Note, triggeredAt: number) => void;

@@ -35,0 +34,0 @@ private maxTime;

@@ -60,4 +60,2 @@ import { Envelope as Env } from "tone";

triggerAttack = (note, triggeredAt) => {
if (note.duration)
return this.triggerAttackRelease(note, triggeredAt);
this.activeNote = note.fullName;

@@ -67,10 +65,3 @@ this.triggeredAt = triggeredAt;

};
triggerAttackRelease = (note, triggeredAt) => {
this.activeNote = note.fullName;
this.triggeredAt = triggeredAt;
this.internalModule.triggerAttackRelease(note.duration, triggeredAt);
};
triggerRelease = (note, triggeredAt) => {
if (this.activeNote && this.activeNote !== note.fullName)
return;
this.internalModule.triggerRelease(triggeredAt);

@@ -77,0 +68,0 @@ };

@@ -31,5 +31,6 @@ import { Oscillator as Osc } from "tone";

set range(value: number);
start(): void;
start(time: number): void;
stop(time?: number): void;
triggerAttack: (note: Note, triggeredAt: number) => void;
triggerRelease: (note: Note) => void;
triggerRelease: (note: Note, triggeredAt: number) => void;
private updateFrequency;

@@ -41,4 +42,6 @@ private getNote;

constructor(name: string, props: Partial<OscillatorInterface>);
start(time: number): void;
stop(time?: number): void;
private registerInputs;
}
export {};

@@ -1,2 +0,2 @@

import { Oscillator as Osc } from "tone";
import { now, Oscillator as Osc } from "tone";
import Note from "../Note";

@@ -20,5 +20,3 @@ import Module from "./Base";

});
this.note = new Note("C3");
this.internalModule.sync();
this.internalModule.start();
this.start(now());
}

@@ -78,9 +76,22 @@ get note() {

}
start() {
this.internalModule.start();
start(time) {
const state = this.internalModule.context.transport.state;
if (state !== "started")
return;
const oscState = this.internalModule.state;
if (oscState === "started") {
this.internalModule.restart(time);
}
else {
this.internalModule.start(time);
}
}
stop(time) {
this.internalModule.stop(time);
}
triggerAttack = (note, triggeredAt) => {
this.setNoteAt(note, triggeredAt);
this.start(triggeredAt);
};
triggerRelease = (note) => {
triggerRelease = (note, triggeredAt) => {
// Do nothing

@@ -93,7 +104,5 @@ };

if (time) {
this.internalModule.restart(time);
this.internalModule.frequency.setValueAtTime(freq, time);
}
else {
this.internalModule.restart();
this.internalModule.frequency.value = freq;

@@ -117,2 +126,8 @@ }

}
start(time) {
this.audioModules.forEach((audioModule) => audioModule.start(time));
}
stop(time) {
this.audioModules.forEach((audioModule) => audioModule.stop(time));
}
registerInputs() {

@@ -119,0 +134,0 @@ this.registerInput({

@@ -29,3 +29,3 @@ import MidiEvent from "../MidiEvent";

dispose(): void;
midiTriggered: (midiEvent: MidiEvent, voiceNo: number, noteIndex?: number) => void;
midiTriggered: (midiEvent: MidiEvent, voiceNo?: number, noteIndex?: number) => void;
serialize(): {

@@ -32,0 +32,0 @@ id: string;

@@ -63,3 +63,3 @@ import { v4 as uuidv4 } from "uuid";

}
midiTriggered = (midiEvent, voiceNo, noteIndex) => {
midiTriggered = (midiEvent, voiceNo = 0, noteIndex) => {
const audioModule = this.findVoice(voiceNo);

@@ -66,0 +66,0 @@ audioModule?.midiTriggered(midiEvent, noteIndex);

@@ -20,2 +20,4 @@ import Module, { DummnyInternalModule } from "./Base";

constructor(name: string, props: Partial<ISequencer>);
get props(): ISequencer;
set props(value: ISequencer);
get steps(): number;

@@ -27,8 +29,9 @@ set steps(value: number);

set sequences(value: ISequence[][]);
start(): void;
start(time: number): void;
stop(): void;
private registerOutputs;
private initializePart;
private adjust;
private adjustNumberOfBars;
private adjustNumberOfSequences;
private adjustNumberOfSteps;
private updateBarParts;

@@ -35,0 +38,0 @@ private get loopEnd();

@@ -1,2 +0,2 @@

import { Part, Time } from "tone";
import { now, Part, Time } from "tone";
import Module, { DummnyInternalModule } from "./Base";

@@ -20,5 +20,14 @@ import MidiEvent from "../MidiEvent";

this.initializePart();
this.start();
this.start(now());
this.registerOutputs();
}
get props() {
return super.props;
}
set props(value) {
if (!this.sequences)
this._props["sequences"] = [];
super.props = { ...this.props, ...value };
this.adjust();
}
get steps() {

@@ -29,4 +38,2 @@ return this._props["steps"];

this._props = { ...this.props, steps: value };
this.adjustNumberOfSequences();
this.updateBarParts();
}

@@ -38,5 +45,2 @@ get bars() {

this._props = { ...this.props, bars: value };
this.adjustNumberOfBars();
this.adjustNumberOfSequences();
this.updateBarParts();
}

@@ -49,6 +53,8 @@ get sequences() {

this._props = { ...this.props, sequences };
this.updateBarParts();
}
start() {
this.part.start();
start(time) {
const state = this.part.context.transport.state;
if (state !== "started")
return;
this.part.start(time);
}

@@ -69,2 +75,9 @@ stop() {

}
adjust() {
if (!this.part)
return;
this.adjustNumberOfBars();
this.adjustNumberOfSteps();
this.updateBarParts();
}
adjustNumberOfBars() {

@@ -77,13 +90,5 @@ const currentBar = this.sequences.length;

if (num > 0) {
if (this.part) {
this.part.remove(`${currentBar}:0:0`);
this.part.loopEnd = this.loopEnd;
}
sequences.pop();
}
else {
if (this.part) {
this.part.add(`${currentBar}:0:0`, currentBar);
this.part.loopEnd = this.loopEnd;
}
sequences.push([]);

@@ -94,3 +99,3 @@ }

}
adjustNumberOfSequences(bar = 0) {
adjustNumberOfSteps(bar = 0) {
if (!this.bars)

@@ -104,3 +109,3 @@ return;

return;
this.adjustNumberOfSequences(bar + 1);
this.adjustNumberOfSteps(bar + 1);
return;

@@ -117,3 +122,3 @@ }

this.sequences = allSequences;
this.adjustNumberOfSequences(bar);
this.adjustNumberOfSteps(bar);
}

@@ -126,2 +131,7 @@ updateBarParts() {

});
this.part.clear();
this.barParts.forEach((_, bar) => {
this.part.add(`${bar}:0:0`, bar);
});
this.part.loopEnd = this.loopEnd;
}

@@ -128,0 +138,0 @@ get loopEnd() {

{
"name": "@blibliki/engine",
"version": "0.1.11",
"version": "0.1.12",
"main": "build/index.js",

@@ -5,0 +5,0 @@ "types": "build/index.d.ts",

@@ -1,2 +0,2 @@

import { Context, setContext } from "tone";
import { Context, now, setContext } from "tone";
import MidiDeviceManager from "./MidiDeviceManager";

@@ -55,2 +55,3 @@ import MidiEvent, { EType } from "./MidiEvent";

this.context.transport.start();
this.midiDeviceManager = new MidiDeviceManager();

@@ -64,3 +65,4 @@

registerModule(name: string, type: string, props: any = {}) {
const audioModule = createModule(name, type, props);
const audioModule = createModule(name, type, {});
audioModule.props = props;
this.modules[audioModule.id] = audioModule;

@@ -158,2 +160,34 @@

get isStarted() {
return this.context.transport.state === "started";
}
start() {
const startTime = now();
Object.values(this.modules).forEach((audioModule) => {
const am = audioModule as any;
if (!am.start) return;
am.start(startTime);
});
}
stop() {
const startTime = now();
Object.values(this.modules).forEach((audioModule) => {
const am = audioModule as any;
if (!am.stop) return;
am.stop(startTime);
});
}
get bpm() {
return this.context.transport.bpm.value;
}
set bpm(value: number) {
this.context.transport.bpm.value = value;
}
private applyRoutesRequired(audioModule: AudioModule, props: any) {

@@ -160,0 +194,0 @@ if (!props.polyNumber) return false;

@@ -18,3 +18,2 @@ import { v4 as uuidv4 } from "uuid";

triggerRelease: Function;
triggerAttackRelease: Function;
}

@@ -134,13 +133,24 @@

triggerAttackRelease(note: Note, triggeredAt: number) {
throw Error("triggerAttackRelease not implemented");
}
midiTriggered = (midiEvent: MidiEvent, noteIndex?: number) => {
const { notes, triggeredAt } = midiEvent;
midiTriggered = (midiEvent: MidiEvent, noteIndex?: number) => {
switch (midiEvent.type) {
case "noteOn":
this.triggerer(this.triggerAttack, midiEvent, noteIndex);
const { duration } = notes[0];
this.triggerer(this.triggerAttack, notes, triggeredAt, noteIndex);
if (duration) {
const releaseTriggeredAt =
triggeredAt + (this.internalModule as any).toSeconds(duration);
this.triggerer(
this.triggerRelease,
notes,
releaseTriggeredAt,
noteIndex
);
}
break;
case "noteOff":
this.triggerer(this.triggerRelease, midiEvent, noteIndex);
this.triggerer(this.triggerRelease, notes, triggeredAt, noteIndex);
break;

@@ -154,7 +164,6 @@ default:

trigger: Function,
midiEvent: MidiEvent,
notes: Note[],
triggeredAt: number,
noteIndex?: number
) {
const { notes, triggeredAt } = midiEvent;
if (noteIndex !== undefined && this.voiceNo !== undefined) {

@@ -161,0 +170,0 @@ trigger(notes[noteIndex], triggeredAt);

@@ -93,18 +93,9 @@ import { Envelope as Env } from "tone";

triggerAttack = (note: Note, triggeredAt: number) => {
if (note.duration) return this.triggerAttackRelease(note, triggeredAt);
this.activeNote = note.fullName;
this.triggeredAt = triggeredAt;
this.internalModule.triggerAttack(triggeredAt);
};
triggerAttackRelease = (note: Note, triggeredAt: number) => {
this.activeNote = note.fullName;
this.triggeredAt = triggeredAt;
this.internalModule.triggerAttackRelease(note.duration, triggeredAt);
};
triggerRelease = (note: Note, triggeredAt: number) => {
if (this.activeNote && this.activeNote !== note.fullName) return;
this.internalModule.triggerRelease(triggeredAt);

@@ -111,0 +102,0 @@ };

@@ -1,2 +0,1 @@

import MidiEvent from "../MidiEvent";
import { now, Oscillator as Osc, ToneOscillatorType } from "tone";

@@ -35,6 +34,3 @@

this.note = new Note("C3");
this.internalModule.sync();
this.internalModule.start();
this.start(now());
}

@@ -112,11 +108,25 @@

start() {
this.internalModule.start();
start(time: number) {
const state = this.internalModule.context.transport.state;
if (state !== "started") return;
const oscState = this.internalModule.state;
if (oscState === "started") {
this.internalModule.restart(time);
} else {
this.internalModule.start(time);
}
}
stop(time?: number) {
this.internalModule.stop(time);
}
triggerAttack = (note: Note, triggeredAt: number) => {
this.setNoteAt(note, triggeredAt);
this.start(triggeredAt);
};
triggerRelease = (note: Note) => {
triggerRelease = (note: Note, triggeredAt: number) => {
// Do nothing

@@ -131,6 +141,4 @@ };

if (time) {
this.internalModule.restart(time);
this.internalModule.frequency.setValueAtTime(freq, time);
} else {
this.internalModule.restart();
this.internalModule.frequency.value = freq;

@@ -162,2 +170,10 @@ }

start(time: number) {
this.audioModules.forEach((audioModule) => audioModule.start(time));
}
stop(time?: number) {
this.audioModules.forEach((audioModule) => audioModule.stop(time));
}
private registerInputs() {

@@ -164,0 +180,0 @@ this.registerInput({

@@ -95,3 +95,3 @@ import MidiEvent from "../MidiEvent";

midiEvent: MidiEvent,
voiceNo: number,
voiceNo: number = 0,
noteIndex?: number

@@ -98,0 +98,0 @@ ) => {

@@ -1,2 +0,2 @@

import { Part, Time } from "tone";
import { now, Part, Time } from "tone";
import Module, { DummnyInternalModule } from "./Base";

@@ -40,6 +40,17 @@ import { INote } from "../Note";

this.initializePart();
this.start();
this.start(now());
this.registerOutputs();
}
get props() {
return super.props;
}
set props(value: ISequencer) {
if (!this.sequences) this._props["sequences"] = [];
super.props = { ...this.props, ...value };
this.adjust();
}
get steps() {

@@ -51,4 +62,2 @@ return this._props["steps"];

this._props = { ...this.props, steps: value };
this.adjustNumberOfSequences();
this.updateBarParts();
}

@@ -62,5 +71,2 @@

this._props = { ...this.props, bars: value };
this.adjustNumberOfBars();
this.adjustNumberOfSequences();
this.updateBarParts();
}

@@ -75,7 +81,9 @@

this._props = { ...this.props, sequences };
this.updateBarParts();
}
start() {
this.part.start();
start(time: number) {
const state = this.part.context.transport.state;
if (state !== "started") return;
this.part.start(time);
}

@@ -101,2 +109,10 @@

private adjust() {
if (!this.part) return;
this.adjustNumberOfBars();
this.adjustNumberOfSteps();
this.updateBarParts();
}
private adjustNumberOfBars() {

@@ -110,12 +126,4 @@ const currentBar = this.sequences.length;

if (num > 0) {
if (this.part) {
this.part.remove(`${currentBar}:0:0`);
this.part.loopEnd = this.loopEnd;
}
sequences.pop();
} else {
if (this.part) {
this.part.add(`${currentBar}:0:0`, currentBar);
this.part.loopEnd = this.loopEnd;
}
sequences.push([]);

@@ -128,3 +136,3 @@ }

private adjustNumberOfSequences(bar = 0) {
private adjustNumberOfSteps(bar = 0) {
if (!this.bars) return;

@@ -139,3 +147,3 @@

this.adjustNumberOfSequences(bar + 1);
this.adjustNumberOfSteps(bar + 1);
return;

@@ -153,3 +161,3 @@ }

this.adjustNumberOfSequences(bar);
this.adjustNumberOfSteps(bar);
}

@@ -164,2 +172,8 @@

});
this.part.clear();
this.barParts.forEach((_, bar) => {
this.part.add(`${bar}:0:0`, bar);
});
this.part.loopEnd = this.loopEnd;
}

@@ -166,0 +180,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc