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 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
) {
const chord = [];
import Tone from 'tone';
import { Scale, Note, Chord } from 'tonal';
import { of, from, Observable } from 'rxjs';
import { repeat, mergeMap, filter } from 'rxjs/operators';
import fetchSpecFile from '@generative-music/samples.generative.fm/browser-client';
const toss = (pcs = [], octaves = []) =>
octaves.reduce(
(notes, octave) => notes.concat(pcs.map(pc => `${pc}${octave}`)),
[]
);
const OCTAVES = [4];
const TONIC = 'C';
const SCALE = 'major';
const PITCH_CLASSES = Scale.notes(TONIC, SCALE);
const NOTES = toss(PITCH_CLASSES, OCTAVES);
const CHORDS_BY_NOTE = Scale.chords(SCALE)
.filter(name => name !== '5' && name !== '64')
.reduce(
(chords, name) =>
chords.concat(
OCTAVES.map(octave => Chord.notes(`${TONIC}${octave}${name}`))
),
[]
)
.reduce((map, chord) => {
chord.forEach(note => {
if (map.has(note)) {
map.set(note, map.get(note).concat([chord]));
} else {
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
) {
const chord = [];
mergeMap,
delayWhen,
filter,
} from 'rxjs/operators';
import getSampledInstrument from '../util/get-sampled-instrument';
const toss = (pcs = [], octaves = []) =>
octaves.reduce(
(notes, octave) => notes.concat(pcs.map(pc => `${pc}${octave}`)),
[]
);
const OCTAVES = [4];
const TONIC = 'C';
const SCALE = 'major';
const PITCH_CLASSES = Scale.notes(TONIC, SCALE);
const NOTES = toss(PITCH_CLASSES, OCTAVES);
const CHORDS_BY_NOTE = Scale.chords(SCALE)
.filter(name => name !== '5' && name !== '64')
.reduce(
(chords, name) =>
chords.concat(
OCTAVES.map(octave => Chord.notes(`${TONIC}${octave}${name}`))
),
[]
)
.reduce((map, chord) => {
chord.forEach(note => {
if (map.has(note)) {
map.set(note, map.get(note).concat([chord]));
} else {
const getInstrument = samplesByNote =>
new Promise(resolve => {
const instrument = new Tone.Sampler(samplesByNote, {
onload: () => resolve(instrument),
});
});
const toss = (pcs = [], octaves = []) =>
octaves.reduce(
(notes, octave) => notes.concat(pcs.map(pc => `${pc}${octave}`)),
[]
);
const OCTAVES = [3, 4, 5];
const NOTES = toss(Scale.notes('C major'), OCTAVES);
const MELODY_DISTANCE = 3;
const melodyFromNote = (
note = NOTES[Math.floor(Math.random() * NOTES.length)]
) => {
const index = NOTES.findIndex(n => n === note);
const min = Math.max(index - MELODY_DISTANCE, 0);
const max = Math.min(index + MELODY_DISTANCE + 1, NOTES.length);
return NOTES[Math.floor(Math.random() * (max - min) + min)];
};
const NOTES_PER_SECOND = Math.random() * 2 + 5;
const repeat = (fn, interval) => {
const schedule = time => {
Tone.Transport.scheduleOnce((...args) => {
import { Scale, Note } from 'tonal';
import Tone from 'tone';
import fetchSpecFile from '@generative-music/samples.generative.fm';
const OCTAVES = [3, 4, 5, 6];
const MAX_STEP_DISTANCE = 2;
const MAX_PHRASE_LENGTH = 3;
const PHRASE_P_BASE = 0.5;
const pitchClasses = Scale.notes('C', 'major');
const notes = OCTAVES.reduce(
(allNotes, octave) =>
allNotes.concat(pitchClasses.map(pc => `${pc}${octave}`)),
[]
);
const getNextNotesForNote = note => {
const index = notes.findIndex(n => n === note);
const lowestIndex = Math.max(0, index - MAX_STEP_DISTANCE);
return notes
.slice(lowestIndex, index)
.concat(notes.slice(index + 1, index + MAX_STEP_DISTANCE + 1));
};
const generatePhrase = (
import { Scale, Note } from 'tonal';
import Tone from 'tone';
import getSampledInstrument from '../util/get-sampled-instrument';
const OCTAVES = [3, 4, 5, 6];
const MAX_STEP_DISTANCE = 2;
const MAX_PHRASE_LENGTH = 3;
const PHRASE_P_BASE = 0.5;
const pitchClasses = Scale.notes('C', 'major');
const notes = OCTAVES.reduce(
(allNotes, octave) =>
allNotes.concat(pitchClasses.map(pc => `${pc}${octave}`)),
[]
);
const getNextNotesForNote = note => {
const index = notes.findIndex(n => n === note);
const lowestIndex = Math.max(0, index - MAX_STEP_DISTANCE);
return notes
.slice(lowestIndex, index)
.concat(notes.slice(index + 1, index + MAX_STEP_DISTANCE + 1));
};
const generatePhrase = (
(allNotes, octave) =>
allNotes.concat(Scale.notes(`${tonicPc}${octave}`, 'major')),
[]
const majorScales = Note.names().map(tonic =>
Scale.notes(tonic, 'major')
.map(note => Note.simplify(note))
.map(note => (note.includes('b') ? Note.enharmonic(note) : note))
);