How to use the tonal.Distance.semitones function in tonal

To help you get started, we’ve selected a few tonal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github felixroos / harmonical / src / util_old.ts View on Github external
  if (notes.find(note => Distance.semitones(note, range[0]) > 0)) {
    notes = notes.map(note => Distance.transpose(note, '8P'));
github felixroos / harmonical / src / util.ts View on Github external
export function isInRange(note, range) {
  return Distance.semitones(note, range[0]) <= 0 && Distance.semitones(note, range[1]) >= 0;
}
/** Returns array of distances from the given notes to the range ends  */
github generative-music / pieces-alex-bainter / packages / piece-moment / src / piece.js View on Github external
) => note => {
        const closestSampledNote = findClosest(samplesByNote, note);
        const difference = Distance.semitones(closestSampledNote, note);
        const buffer = buffers.get(closestSampledNote);
        const pitchShiftSemitones = Math.random() < 1 ? 0 : 12;
        const playbackRate = Tone.intervalToFrequencyRatio(
          difference - pitchShiftSemitones
        );
        const source = new Tone.BufferSource(buffer)
          .set(
            Object.assign({}, opts, {
              playbackRate,
              onended: () => {
                const i = activeSources.indexOf(source);
                if (i >= 0) {
                  activeSources.splice(i, 1);
                }
              },
            })
github generative-music / pieces-alex-bainter / packages / piece-homage / src / piece.js View on Github external
) => note => {
        const closestSampledNote = findClosest(samplesByNote, note);
        const difference = Distance.semitones(closestSampledNote, note);
        const buffer = buffers.get(closestSampledNote);
        const playbackRate = Tone.intervalToFrequencyRatio(difference - 24);
        const source = new Tone.BufferSource(buffer)
          .set({
            playbackRate,
            onended: () => {
              const i = activeSources.indexOf(source);
              if (i >= 0) {
                activeSources.splice(i, 1);
              }
            },
          })
          .connect(noteDestination);
        activeSources.push(source);
        source.start('+1');
      };
github generative-music / pieces-alex-bainter / packages / piece-drones-2 / src / piece.js View on Github external
const drone = (
          note,
          droneDestination,
          pitchShift = 0,
          reverse = false
        ) => {
          const closestSampledNote = findClosest(samplesByNote, note);
          const difference = Distance.semitones(closestSampledNote, note);
          const playbackRate = Tone.intervalToFrequencyRatio(
            difference + pitchShift
          );
          const buffer = buffers.get(closestSampledNote);
          if (!disposableNodes.includes(buffer)) {
            disposableNodes.push(buffer);
          }
          const source = new Tone.BufferSource(buffer)
            .set({
              reverse,
              playbackRate,
              onended: () => {
                const i = disposableNodes.indexOf(source);
                if (i >= 0) {
                  source.dispose();
                  disposableNodes.splice(i, 1);
github generative-music / pieces-alex-bainter / packages / piece-drones / src / piece.js View on Github external
const drone = (
              note,
              droneDestination,
              pitchShift = 0,
              reverse = false
            ) => {
              const closestSampledNote = findClosest(samplesByNote, note);
              const difference = Distance.semitones(closestSampledNote, note);
              const playbackRate = Tone.intervalToFrequencyRatio(
                difference + pitchShift
              );
              const buffer = buffers.get(closestSampledNote);
              const source = new Tone.BufferSource(buffer)
                .set({
                  reverse,
                  playbackRate,
                  onended: () => {
                    const index = disposableNodes.indexOf(source);
                    if (index >= 0) {
                      source.dispose();
                      disposableNodes.splice(index, 1);
                    }
                  },
                })
github felixroos / harmonical / src / util_old.ts View on Github external
export function isInRange(note, range) {
  return Distance.semitones(note, range[0]) <= 0 && Distance.semitones(note, range[1]) >= 0;
}
github generative-music / pieces-alex-bainter / packages / piece-day-dream / src / piece.js View on Github external
const secondsPastNoon =
              hoursPastNoon * 60 * 60 + minute * 60 + second;
            const pctToMidnight = secondsPastNoon / (12 * 60 * 60 - 1);
            semitoneChange =
              pctToMidnight *
                (MIDNIGHT_SEMITONE_CHANGE - NOON_SEMITONE_CHANGE) +
              NOON_SEMITONE_CHANGE;
          } else {
            const secondsPastMidnight = hour * 60 * 60 + minute * 60 + second;
            const pctToNoon = secondsPastMidnight / (12 * 60 * 60 - 1);
            semitoneChange =
              pctToNoon * (NOON_SEMITONE_CHANGE - MIDNIGHT_SEMITONE_CHANGE) +
              MIDNIGHT_SEMITONE_CHANGE;
          }
          const closestSample = findClosest(note, samplesByNote);
          const difference = Distance.semitones(closestSample, note);
          const buffer = buffers.get(closestSample);
          const bufferSource = new Tone.BufferSource(buffer).connect(
            destination
          );
          const playbackRate = Tone.intervalToFrequencyRatio(
            difference - semitoneChange
          );
          bufferSource.set({
            playbackRate,
            onended: () => {
              const index = bufferSources.indexOf(bufferSource);
              if (index >= 0) {
                bufferSource.dispose();
                bufferSources.splice(index, 1);
              }
            },
github generative-music / pieces-alex-bainter / packages / piece-substrate / src / piece.js View on Github external
) => (note, time = 0) => {
          const closestSampledNote = findClosest(samplesByNote, note);
          const difference = Distance.semitones(closestSampledNote, note);
          const buffer = buffers.get(closestSampledNote);
          const playbackRate = Tone.intervalToFrequencyRatio(
            difference + semitoneChange
          );
          const source = new Tone.BufferSource(buffer)
            .set({
              playbackRate,
              fadeIn,
              curve: 'linear',
              onended: () => {
                const i = activeSources.indexOf(source);
                if (i >= 0) {
                  activeSources.splice(i, 1);
                }
              },
            })