Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (notes.find(note => Distance.semitones(note, range[0]) > 0)) {
notes = notes.map(note => Distance.transpose(note, '8P'));
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 */
) => 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);
}
},
})
) => 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');
};
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);
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);
}
},
})
export function isInRange(note, range) {
return Distance.semitones(note, range[0]) <= 0 && Distance.semitones(note, range[1]) >= 0;
}
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);
}
},
) => (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);
}
},
})