Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import Tone from 'tone';
import { Scale, Note } from 'tonal';
import getSampledInstrument from '../util/get-sampled-instrument';
const tonic = Note.names()[Math.floor(Math.random() * Note.names().length)];
const scalePitchClasses = Scale.notes(tonic, 'major');
const notes = [3, 4, 5, 6].reduce(
(allNotes, octave) =>
allNotes.concat(scalePitchClasses.map(pc => `${pc}${octave}`)),
[]
);
const getOffsetProgression = () => {
const progression = [];
const startingStep = Math.random() < 0.5 ? 0 : 1;
const largestStep = Math.random() * (5 - startingStep) + startingStep;
for (
let step = startingStep;
step <= largestStep;
step += Math.random() < 0.5 ? 1 : 2
) {
import Tone from 'tone';
import { Scale, Note } from 'tonal';
import fetchSpecFile from '@generative-music/samples.generative.fm/browser-client';
const tonic = Note.names()[Math.floor(Math.random() * Note.names().length)];
const scalePitchClasses = Scale.notes(tonic, 'major');
const notes = [3, 4, 5, 6].reduce(
(allNotes, octave) =>
allNotes.concat(scalePitchClasses.map(pc => `${pc}${octave}`)),
[]
);
const getOffsetProgression = () => {
const progression = [];
const startingStep = Math.random() < 0.5 ? 0 : 1;
const largestStep = Math.random() * (5 - startingStep) + startingStep;
for (
let step = startingStep;
step <= largestStep;
step += Math.random() < 0.5 ? 1 : 2
) {
import { Scale, Note } from 'tonal';
const majorScales = Note.names().map(tonic =>
Scale.notes(tonic, 'major')
.map(note => Note.simplify(note))
.map(note => (note.includes('b') ? Note.enharmonic(note) : note))
);
const majorScalesWithNotes = notes =>
majorScales.filter(scaleNotes =>
notes.every(note => scaleNotes.includes(note))
);
const getSimilarPitchClasses = (includingPitchClasses = []) => {
const compatibleMajorScales = majorScalesWithNotes(includingPitchClasses);
const randomCompatibleScale =
compatibleMajorScales[
Math.floor(Math.random() * compatibleMajorScales.length)
];
const SECOND_NOTE_DELAY_MULTIPLIER_S = 15;
const MIN_SECOND_NOTE_DELAY_S = 1;
const LOW_OCTAVE_1 = 1;
const LOW_OCTAVE_2 = 2;
const HIGH_OCTAVE_1 = 3;
const HIGH_OCTAVE_2 = 4;
const LOWER_OCTAVES = [LOW_OCTAVE_1, LOW_OCTAVE_2];
const HIGHER_OCTAVES = [HIGH_OCTAVE_1, HIGH_OCTAVE_2];
const MIN_LOW_NOTE_DELAY_S = 2;
const MIN_HIGH_NOTE_DELAY_S = 5;
const MIN_LOW_NOTE_INTERVAL_S = 45;
const MIN_HIGH_NOTE_INTERVAL_S = 75;
const INTERVAL_MULTIPLIER_S = 5;
const VOLUME_ADJUSTMENT = -15;
const tonicPitchClasses = Note.names().slice(
0,
NUM_POTENTIAL_TONIC_PITCH_CLASSES
);
const tonicPitchClass = pickRandomFromArray(tonicPitchClasses);
const pitchClassesOverOctaves = (pitchClasses, octaves) =>
pitchClasses.reduce(
(notes, pitchClass) =>
notes.concat(octaves.map(octave => `${pitchClass}${octave}`)),
[]
);
const lowPitchClasses = [
tonicPitchClass,
Distance.transpose(tonicPitchClass, 'P5'),
];
(allNotes, octave) =>
allNotes.concat(Note.names().map(pitchClass => `${pitchClass}${octave}`)),
[]
while (index1 === index2) {
index2 = Math.floor(Math.random() * copy.length);
}
const tmp = copy[index1];
copy[index1] = copy[index2];
copy[index2] = tmp;
return copy;
};
function* makeNoteGenerator(notes) {
for (let i = 0; i < notes.length; i += 1) {
yield notes[i];
}
}
const PITCH_CLASSES = Note.names();
const makePiece = ({
audioContext,
destination,
preferredFormat,
sampleSource = {},
}) =>
fetchSpecFile(sampleSource.baseUrl, sampleSource.specFilename).then(
({ samples }) => {
if (Tone.context !== audioContext) {
Tone.setContext(audioContext);
}
const masterVol = new Tone.Volume(5).connect(destination);
const marimbaSamplesByNote = samples['vsco2-marimba'][preferredFormat];
const pianoSamplesByNote = samples['vsco2-piano-mf'][preferredFormat];
return Promise.all([
(allNotes, octave) =>
allNotes.concat(Note.names().map(pitchClass => `${pitchClass}${octave}`)),
[]