@generative-music/sample-index-transformer

0.1.1 • Public • Published

sample-index-transformer

Transforms sample file indices.

Usage

This package exports a function which requires an object parameter that adheres to the schema defined in @generative-music/sample-index-schema, an array of sample group names to transform, and a transformation function.

import transform from '@generative-music/sample-index-transformer';

const sampleIndex = {
  piano: {
    C4: 'url/to/c4.wav',
    C5: 'url/to/c5.wav',
  },
  drum: ['url/to/hit/1.wav', 'url/to/hit/2.wav'],
};

transform(sampleIndex, ['piano'], window.fetch).then((fetchIndex) => {
  const { piano } = fetchIndex;
  console.log(piano); // { C4: <Response>, C5: <Response> }
});

transform()

A function which applies a given transformation to the specified samples within a sample index group.

Syntax

const transformationPromise = transform(
  sampleIndex,
  sampleNames,
  transformation
);
Parameters
  • sampleIndex (Optional): An object which adheres to the schema defined in @generative-music/sample-index-schema. Defaults to an empty object ({}).
  • sampleNames (Optional): An array of strings which correspond to property names in sampleIndex. The samples associated with these property names will be transformed and returned. Defaults to an empty array ([]).
  • transformation (Optional): A function which will be called for every sample value from sampleIndex and selected by sampleNames and returns a Promise. Defaults to (value) => Promise.resolve(value).
Return value

A Promise which resolves to an object that adheres to the schema defined in @generative-music/sample-index-schema. Only properties specified by sampleNames will be present, with the resolved values from transformation as the sample values.

Readme

Keywords

none

Package Sidebar

Install

npm i @generative-music/sample-index-transformer

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

7.85 kB

Total Files

8

Last publish

Collaborators

  • metalex9