Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.sequence = new Sequence((time, col) => {
this.beat = col;
setCurrentBeat(this.beat);
// 16 columns, each column: ex. [1, 0, 0, 0, 1, 1, 0, 1]
const column = this.matrix[col];
const nowPlayingAni = [];
for (let i = 0; i < this.notes.length; i += 1) {
if (col === 0 && i === 0 && this.checkStart === false && this.recording === true) {
this.checkStart = true;
this.startTime = now();
}
// make sure no play while loading
if (column[i] === 1 && !this.loadingSamples) {
const vel = (Math.random() * 0.5) + 0.5;
// convert velocity(gain) to volume
this.samples.volume.value = 10 * Math.log10(vel);
// console.log('nowTime: ', now());
// console.log('Transport.seconds: ', Transport.seconds);
// console.log('time: ', time);
// this.samples._players[this.notes[i]].start(time, 0, 0.5);
this.samples._players[this.notes[i]].start(time);
nowPlayingAni.push(i);
}
}
playDrumAni(nowPlayingAni);
playNoteDown(
pitch: number, velocity: number,
output: any) { // tslint:disable-line:no-any
const buffer = this.getBuffer(pitch, velocity);
const source = new Tone.BufferSource(buffer).connect(output);
source.start(0, 0, undefined, 1, 0);
if (this.sourceMap.has(pitch)) {
this.sourceMap.get(pitch).stop(
(Tone.now() as number) + this.FADE_SECONDS, this.FADE_SECONDS);
}
this.sourceMap.set(pitch, source);
}
function getTimingOffset(){
return performance.now() - Tone.now() * 1000
}
const noteSubscription = notes$.subscribe(note => {
if (
Math.random() < 0.1 &&
Note.oct(note) > 3 &&
Tone.now() - lastViolinTimeS > 20
) {
lastViolinTimeS = Tone.now();
violin.triggerAttack(note, '+1');
} else {
piano.triggerAttack(note, '+1');
}
});
return () => {
playRecord(record, aniTrigger) {
this.recordStartTime = now();
for (let i = 0; i < record.content.length; i += 1) {
const time = this.recordStartTime + (record.content[i].time - record.startTime);
this.samples.get(record.content[i].key).start(time).toMaster();
Transport.schedule(() => {
aniTrigger(record.content[i].key);
}, time);
}
}
stem.url, () => {
stem.player.loopStart = stem.loopStart;
stem.player.loopEnd = stem.loopEnd;
stem.player.loop = stem.loop;
if (Transport.state === 'stopped') {
Transport.start(now() + stem.loopStart, 0);
stem.player.start(now(), 0);
} else {
stem.player.volume.value = -100;
stem.player.volume.rampTo(stem.volume, 1);
const offset = Transport.seconds % stem.loopDuration;
stem.player.start(now(), offset + stem.loopStart);
}
this.stems[stem.slug] = stem;
resolve({stem: stem, analyser: fft._analyser});
}).fan(fft).toMaster();
});
stem.url, () => {
stem.player.loopStart = stem.loopStart;
stem.player.loopEnd = stem.loopEnd;
stem.player.loop = stem.loop;
if (Transport.state === 'stopped') {
Transport.start(now() + stem.loopStart, 0);
stem.player.start(now(), 0);
} else {
stem.player.volume.value = -100;
stem.player.volume.rampTo(stem.volume, 1);
const offset = Transport.seconds % stem.loopDuration;
stem.player.start(now(), offset + stem.loopStart);
}
this.stems[stem.slug] = stem;
resolve({stem: stem, analyser: fft._analyser});
}).fan(fft).toMaster();
});
Transport.scheduleOnce(() => {
regularInstrument.triggerAttack(
extraNote,
now(),
EXTRA_NOTE_VELOCITY
);
}, `+${durationsByMidi[midi] / 4}`);
} else if (Math.random() < EXTRA_CHORD_CHANCE_P) {
getInstrument().then(instrument => () => ({ yPct, velocity }) => {
const note = getNoteAtHeight(yPct);
instrument.triggerAttack(note, now() + NOTE_TIME_OFFSET_S, velocity);
});