Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function getDegreeInChord(degree, chord) {
chord = Harmony.getTonalChord(chord);
const intervals = Chord.intervals(chord);
const tokens = Chord.tokenize(chord);
return Distance.transpose(tokens[0], findDegree(degree, intervals));
}
return notes.reduce((absolute, current, index, notes) => {
if (index === 0) {
return [current + octave];
}
let interval = Distance.interval(notes[index - 1], current);
interval = Harmony.minInterval(interval, direction);
if (interval === '1P') {
interval = direction === 'down' ? '-8P' : '8P';
}
absolute.push(Distance.transpose(absolute[index - 1], interval + ''));
return absolute;
}, []);
}
export function getDegreeInChord(degree, chord) {
chord = Harmony.getTonalChord(chord);
const intervals = Chord.intervals(chord);
const tokens = Chord.tokenize(chord);
return Distance.transpose(tokens[0], findDegree(degree, intervals));
}
const upOctave = (note) => Distance.transpose(note, "8M")
const addNewRootToNotes = (notes, denominator, baseKey) => {
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'),
];
const highPitchClasses = lowPitchClasses.concat(
['M2', 'P4'].map(interval => Distance.transpose(tonicPitchClass, interval))
);
const lowNotes = pitchClassesOverOctaves(lowPitchClasses, LOWER_OCTAVES);
const highNotes = pitchClassesOverOctaves(highPitchClasses, HIGHER_OCTAVES);
const startInterval = (
notes,
minIntervalInSeconds,
minDelayInSeconds,
instrument
) => {
const playNotes = () => {
instrument.triggerAttack(pickRandomFromArray(notes), '+1');
if (Math.random() > P_SECOND_NOTE) {
const playNextNote = () => {
const { value } = ragaGenerator.next();
const [interval, time] = value;
const note = Distance.transpose(
tonic,
Interval.fromSemitones(interval)
);
playNote(note);
if (Math.random() < (interval === 0 || interval === 12 ? 0.5 : 0.1)) {
const lowNote =
Math.random() < 0.5
? 'C#3'
: Distance.transpose(note, Interval.fromSemitones(-12));
playNote(lowNote);
}
Tone.Transport.scheduleOnce(() => {
if (time > 8 && Math.random() < 0.4) {
tonic = tonic === 'C#4' ? 'C#5' : 'C#4';
}
playNextNote();
return notes.map(note => Distance.transpose(note, interval));
}
const playNextNote = () => {
const { value } = ragaGenerator.next();
const [interval, time] = value;
const note = Distance.transpose(
tonic,
Interval.fromSemitones(interval)
);
playNote(note);
if (Math.random() < (interval === 0 || interval === 12 ? 0.5 : 0.1)) {
const lowNote =
Math.random() < 0.5
? 'C#3'
: Distance.transpose(note, Interval.fromSemitones(-12));
playNote(lowNote);
}
Tone.Transport.scheduleOnce(() => {
if (time > 8 && Math.random() < 0.4) {
tonic = tonic === 'C#4' ? 'C#5' : 'C#4';
}
playNextNote();
}, `+${time + Math.random() - 0.5}`);
};
return notes.reduce((absolute, current, index, notes) => {
if (index === 0) {
return [current + octave];
}
let interval = Distance.interval(notes[index - 1], current);
interval = Harmony.minInterval(interval, direction);
if (interval === '1P') {
interval = direction === 'down' ? '-8P' : '8P';
}
absolute.push(Distance.transpose(absolute[index - 1], interval + ''));
return absolute;
}, []);
}