smplr 0.14.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -121,6 +121,7 @@ All instruments share some configuration options that are passed as second argum
121
121
  - `volume`: A number from 0 to 127 representing the instrument global volume. 100 by default
122
122
  - `destination`: An `AudioNode` that is the output of the instrument. `AudioContext.destination` is used by default
123
123
  - `volumeToGain`: a function to convert the volume to gain. It uses MIDI standard as default.
124
+ - `disableScheduler`: disable internal scheduler. `false` by default.
124
125
  - `scheduleLookaheadMs`: the lookahead of the scheduler. If the start time of the note is less than current time plus this lookahead time, the note will be started. 200ms by default.
125
126
  - `scheduleIntervalMs`: the interval of the scheduler. 50ms by default.
126
127
  - `onStart`: a function that is called when starting a note. It receives the note started as parameter. Bear in mind that the time this function is called is not precise, and it's determined by lookahead.
@@ -498,7 +499,7 @@ import { Versilian, getVersilianInstruments } from "smplr";
498
499
  const instrumentNames = await getVersilianInstruments();
499
500
 
500
501
  const context = new AudioContext();
501
- const sampler = new Versilian(context, { instrument: instrumentNAmes[0] });
502
+ const sampler = new Versilian(context, { instrument: instrumentNames[0] });
502
503
  ```
503
504
 
504
505
  ### Soundfont2Sampler
@@ -510,7 +511,7 @@ import { Soundfont2Sampler } from "smplr";
510
511
  import { SoundFont2 } from "soundfont2";
511
512
 
512
513
  const context = new AudioContext();
513
- const sampler = Soundfont2Sampler(context, {
514
+ const sampler = new Soundfont2Sampler(context, {
514
515
  url: "https://smpldsnds.github.io/soundfonts/soundfonts/galaxy-electric-pianos.sf2",
515
516
  createSoundfont: (data) => new SoundFont2(data),
516
517
  });
package/dist/index.d.mts CHANGED
@@ -232,6 +232,7 @@ declare class Sampler {
232
232
  }
233
233
 
234
234
  type QueuedPlayerConfig = {
235
+ disableScheduler: boolean;
235
236
  scheduleLookaheadMs: number;
236
237
  scheduleIntervalMs: number;
237
238
  onStart?: (sample: SampleStart) => void;
package/dist/index.d.ts CHANGED
@@ -232,6 +232,7 @@ declare class Sampler {
232
232
  }
233
233
 
234
234
  type QueuedPlayerConfig = {
235
+ disableScheduler: boolean;
235
236
  scheduleLookaheadMs: number;
236
237
  scheduleIntervalMs: number;
237
238
  onStart?: (sample: SampleStart) => void;
package/dist/index.js CHANGED
@@ -316,10 +316,11 @@ function compose(a, b) {
316
316
  } : a != null ? a : b;
317
317
  }
318
318
  function getConfig(options) {
319
- var _a, _b;
319
+ var _a, _b, _c;
320
320
  const config = {
321
- scheduleLookaheadMs: (_a = options.scheduleLookaheadMs) != null ? _a : 200,
322
- scheduleIntervalMs: (_b = options.scheduleIntervalMs) != null ? _b : 50,
321
+ disableScheduler: (_a = options.disableScheduler) != null ? _a : false,
322
+ scheduleLookaheadMs: (_b = options.scheduleLookaheadMs) != null ? _b : 200,
323
+ scheduleIntervalMs: (_c = options.scheduleIntervalMs) != null ? _c : 50,
323
324
  onStart: options.onStart,
324
325
  onEnded: options.onEnded
325
326
  };
@@ -357,6 +358,9 @@ var QueuedPlayer = class {
357
358
  }
358
359
  start(sample) {
359
360
  var _a;
361
+ if (__privateGet(this, _config2).disableScheduler) {
362
+ return this.player.start(sample);
363
+ }
360
364
  const context = this.player.context;
361
365
  const now = context.currentTime;
362
366
  const startAt = (_a = sample.time) != null ? _a : now;
@@ -394,6 +398,9 @@ var QueuedPlayer = class {
394
398
  }
395
399
  stop(sample) {
396
400
  var _a;
401
+ if (__privateGet(this, _config2).disableScheduler) {
402
+ return this.player.stop(sample);
403
+ }
397
404
  this.player.stop(sample);
398
405
  if (!sample) {
399
406
  __privateGet(this, _queue).clear();