How to use the tone.now function in tone

To help you get started, we’ve selected a few tone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vibertthio / beact / src / utils / Audio.js View on Github external
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);
github tensorflow / magenta-js / music / src / core / soundfont.ts View on Github external
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);
  }
github SonyCSLParis / NONOTO / src / renderer / playback.ts View on Github external
function getTimingOffset(){
    return performance.now() - Tone.now() * 1000
}
github generative-music / pieces-alex-bainter / packages / piece-observable-streams / src / piece.js View on Github external
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 () => {
github vibertthio / beact / src / utils / Audio.js View on Github external
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);
    }
  }
github googlecreativelab / mix-lab / website / src / app / classes / stem-player.ts View on Github external
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();
    });
github googlecreativelab / mix-lab / website / src / app / classes / stem-player.ts View on Github external
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();
    });
github generative-music / pieces-alex-bainter / packages / piece-impact / src / piece.js View on Github external
Transport.scheduleOnce(() => {
            regularInstrument.triggerAttack(
              extraNote,
              now(),
              EXTRA_NOTE_VELOCITY
            );
          }, `+${durationsByMidi[midi] / 4}`);
        } else if (Math.random() < EXTRA_CHORD_CHANCE_P) {
github generative-music / blossom / src / audio / get-player.js View on Github external
getInstrument().then(instrument => () => ({ yPct, velocity }) => {
    const note = getNoteAtHeight(yPct);
    instrument.triggerAttack(note, now() + NOTE_TIME_OFFSET_S, velocity);
  });