Documentation
    Preparing search index...

    Class Part<ValueType>

    Part is a collection ToneEvents which can be started/stopped and looped as a single unit.

    const synth = new Tone.Synth().toDestination();
    const part = new Tone.Part(((time, note) => {
    // the notes given as the second element in the array
    // will be passed in as the second argument
    synth.triggerAttackRelease(note, "8n", time);
    }), [[0, "C2"], ["0:2", "C3"], ["0:3:2", "G2"]]).start(0);
    Tone.Transport.start();
    const synth = new Tone.Synth().toDestination();
    // use an array of objects as long as the object has a "time" attribute
    const part = new Tone.Part(((time, value) => {
    // the value is an object which contains both the note and the velocity
    synth.triggerAttackRelease(value.note, "8n", time, value.velocity);
    }), [{ time: 0, note: "C3", velocity: 0.9 },
    { time: "0:2", note: "C4", velocity: 0.5 }
    ]).start(0);
    Tone.Transport.start();

    Type Parameters

    • ValueType = any

    Hierarchy (View Summary)

    Index
    _humanize: boolean | Time

    the amount of variation from the given time.

    _loop: number | boolean

    Loop value

    _loopEnd: number

    When the note is scheduled to start.

    _loopStart: number

    When the note is scheduled to start.

    _playbackRate: number

    The playback speed of the note. A speed of 1 is no change.

    _probability: number

    private holder of probability value

    _startOffset: number

    A delay time from when the event is scheduled to start

    _state: StateTimeline<{ id: number; offset: number }>

    Tracks the scheduled events

    The callback to invoke.

    context: BaseContext

    The context belonging to the node.

    debug: boolean

    Set this debug flag to log all events that happen in this class.

    mute: boolean

    If mute is true, the callback won't be invoked.

    name: string

    The name of the class

    value: ValueType

    The value which is passed to the callback function.

    version: string

    The version number semver

    • get blockTime(): number

      The number of seconds of 1 processing block (128 samples)

      Returns number

      console.log(Tone.Destination.blockTime);
      
    • get disposed(): boolean

      Indicates if the instance was disposed. 'Disposing' an instance means that all of the Web Audio nodes that were created for the instance are disconnected and freed for garbage collection.

      Returns boolean

    • get humanize(): boolean | Time

      If set to true, will apply small random variation to the callback time. If the value is given as a time, it will randomize by that amount.

      Returns boolean | Time

      const event = new Tone.ToneEvent();
      event.humanize = true;
    • set humanize(variation: boolean | Time): void

      If set to true, will apply small random variation to the callback time. If the value is given as a time, it will randomize by that amount.

      Parameters

      • variation: boolean | Time

      Returns void

      const event = new Tone.ToneEvent();
      event.humanize = true;
    • get length(): number

      The number of scheduled notes in the part.

      Returns number

    • get loop(): number | boolean

      If the part should loop or not between Part.loopStart and Part.loopEnd. If set to true, the part will loop indefinitely, if set to a number greater than 1 it will play a specific number of times, if set to false, 0 or 1, the part will only play once.

      Returns number | boolean

      const part = new Tone.Part();
      // loop the part 8 times
      part.loop = 8;
    • set loop(loop: number | boolean): void

      If the note should loop or not between ToneEvent.loopStart and ToneEvent.loopEnd. If set to true, the event will loop indefinitely, if set to a number greater than 1 it will play a specific number of times, if set to false, 0 or 1, the part will only play once.

      Parameters

      • loop: number | boolean

      Returns void

    • get loopEnd(): Time

      The loopEnd point determines when it will loop if Part.loop is true.

      Returns Time

    • set loopEnd(loopEnd: Time): void

      The loopEnd point is the time the event will loop if ToneEvent.loop is true.

      Parameters

      Returns void

    • get loopStart(): Time

      The loopStart point determines when it will loop if Part.loop is true.

      Returns Time

    • set loopStart(loopStart: Time): void

      The time when the loop should start.

      Parameters

      Returns void

    • get playbackRate(): number

      The playback rate of the part

      Returns number

    • set playbackRate(rate: number): void

      The playback rate of the event. Defaults to 1.

      Parameters

      • rate: number

      Returns void

      const note = new Tone.ToneEvent();
      note.loop = true;
      // repeat the note twice as fast
      note.playbackRate = 2;
    • get probability(): number

      The probability of the notes being triggered.

      Returns number

    • set probability(prob: number): void

      The probability of the notes being triggered.

      Parameters

      • prob: number

      Returns void

    • get progress(): number

      The current progress of the loop interval. Returns 0 if the event is not started yet or it is not set to loop.

      Returns number

    • get sampleTime(): number

      The duration in seconds of one sample.

      Returns number

    • get startOffset(): number

      The start from the scheduled start time.

      Returns number

    • set startOffset(offset: number): void

      The start from the scheduled start time.

      Parameters

      • offset: number

      Returns void

    • get state(): BasicPlaybackState

      Returns the playback state of the note, either "started" or "stopped".

      Returns BasicPlaybackState

    • Get the duration of the loop.

      Returns number

    • Internal tick method

      Parameters

      • time: number

        The time of the event in seconds

      • Optionalvalue: any

      Returns void

    • Add a an event to the part.

      Parameters

      • obj: { time: Time; [key: string]: any }

      Returns this

      const part = new Tone.Part();
      part.add("1m", "C#+11");
    • Add a an event to the part.

      Parameters

      • time: Time

        The time the note should start. If an object is passed in, it should have a 'time' attribute and the rest of the object will be used as the 'value'.

      • Optionalvalue: any

        Any value to add to the timeline

      Returns this

      const part = new Tone.Part();
      part.add("1m", "C#+11");
    • Get/Set an Event's value at the given time. If a value is passed in and no event exists at the given time, one will be created with that value. If two events are at the same time, the first one will be returned.

      Parameters

      • time: Time

        The time of the event to get or set.

      • Optionalvalue: any

        If a value is passed in, the value of the event at the given time will be set to it.

      Returns ToneEvent<any> | null

      const part = new Tone.Part();
      part.at("1m"); // returns the part at the first measure
      part.at("2m", "C2"); // set the value at "2m" to C2.
      // if an event didn't exist at that time, it will be created.
    • Cancel scheduled state change events: i.e. "start" and "stop".

      Parameters

      Returns this

    • Remove all of the notes from the group.

      Returns this

    • disconnect and dispose.

      Returns this

    • Get the object's attributes.

      Returns ToneEventOptions

      const osc = new Tone.Oscillator();
      console.log(osc.get());
    • Return the current time of the Context clock without any lookAhead.

      Returns number

      setInterval(() => {
      console.log(Tone.immediate());
      }, 100);
    • Prints the outputs to the console log for debugging purposes. Prints the contents only if either the object has a property called debug set to true, or a variable called TONE_DEBUG_CLASS is set to the name of the class.

      Parameters

      • ...args: any[]

      Returns void

      const osc = new Tone.Oscillator();
      // prints all logs originating from this oscillator
      osc.debug = true;
      // calls to start/stop will print in the console
      osc.start();
    • Return the current time of the Context clock plus the lookAhead.

      Returns number

      setInterval(() => {
      console.log(Tone.now());
      }, 100);
    • Remove an event from the part. If the event at that time is a Part, it will remove the entire part.

      Parameters

      • obj: { time: Time; [key: string]: any }

      Returns this

    • Remove an event from the part. If the event at that time is a Part, it will remove the entire part.

      Parameters

      • time: Time

        The time of the event

      • Optionalvalue: any

        Optionally select only a specific event value

      Returns this

    • Set multiple properties at once with an object.

      Parameters

      Returns this

      const filter = new Tone.Filter().toDestination();
      // set values using an object
      filter.set({
      frequency: "C6",
      type: "highpass"
      });
      const player = new Tone.Player("https://tonejs.github.io/audio/berklee/Analogsynth_octaves_highmid.mp3").connect(filter);
      player.autostart = true;
    • Start the part at the given time.

      Parameters

      • Optionaltime: Time

        When to start the part.

      • Optionaloffset: Time

        The offset from the start of the part to begin playing at.

      Returns this

    • Stop the part at the given time.

      Parameters

      • Optionaltime: Time

        When to stop the part.

      Returns this

    • Convert the input to a frequency number

      Parameters

      Returns number

      const gain = new Tone.Gain();
      console.log(gain.toFrequency("4n"));
    • Convert the incoming time to seconds. This is calculated against the current TransportClass bpm

      Parameters

      Returns number

      const gain = new Tone.Gain();
      setInterval(() => console.log(gain.toSeconds("4n")), 100);
      // ramp the tempo to 60 bpm over 30 seconds
      Tone.getTransport().bpm.rampTo(60, 30);
    • Convert the class to a string

      Returns string

      const osc = new Tone.Oscillator();
      console.log(osc.toString());
    • Convert the input time into ticks

      Parameters

      Returns number

      const gain = new Tone.Gain();
      console.log(gain.toTicks("4n"));
    • Returns all of the default options belonging to the class.

      Returns PartOptions<any>