Class Clip

The Clip class represents a collection of notes, control changes, and bends, arranged over a certain number of beats, to allow them to be played in a musical expression.

An example of using a clip to contain the first 2 bars of the melody Twinkle Twinkle Little Star:

 const clip = new shimi.Clip(8)
.addNote([0,1], 1, 'C4', 80)
.addNote([2,3], 1, 'G4', 80)
.addNote([4,5], 1, 'A4', 80)
.addNote(6, 2, 'G4', 80);

Hierarchy

Constructors

  • Parameters

    • duration: number

      How many beats the clip lasts for.

    Returns Clip

Properties

bends: ClipBend[] = []

The collection of pitch bends that the clip contains.

controlChanges: ClipCC[] = []

The collection of control changes that the clip contains.

notes: ClipNote[] = []

The collection of notes that the clip contains.

Accessors

  • get duration(): number
  • The difference between the start and end values.

    Attempts to set this to a negative value will result in an error being thrown.

    Returns number

  • set duration(value: number): void
  • Parameters

    • value: number

    Returns void

  • get end(): number
  • The value which the range ends at.

    Attempts to set this to a value less than start will result in an error being thrown.

    Returns number

  • set end(value: number): void
  • Parameters

    • value: number

    Returns void

  • get start(): number
  • The value which the range starts at.

    Attempts to set this to a value greater than end will result in an error being thrown.

    Returns number

  • set start(value: number): void
  • Parameters

    • value: number

    Returns void

  • get typeName(): string
  • Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable.

    Returns string

Methods

  • Adds a bend to the clip. The start parameter can take an array of values, allowing for multiple similar bends to be added at once.

    Returns

    Returns the Clip object which the bend(s) is being added to.

    Parameters

    • start: number | number[]

      What beat within the clip that the bend starts

    • duration: number

      How many beats the bend lasts

    • percent: number | ITween

      How much bend to apply, valid values range from 0 - 127, or a Tween object which defines a strategy for how to change over the course of the bend's lifetime.

    • channel: number = null

      Which channel to play the bend on, valid values range from 0 - 15, or null to allow whatever is playing the clip to decide

    Returns Clip

  • Adds a control change to the clip. The start parameter can take an array of values, allowing for multiple similar control changes to be added at once.

    Returns

    Returns the Clip object which the control change(s) is being added to.

    Parameters

    • start: number | number[]

      What beat within the clip that the control change starts. Can take array of multiple start values.

    • duration: number

      How many beats the control change lasts.

    • controller: number

      The MIDI controller to modify, valid values range from 0 - 127.

    • value: number | ITween

      The value to set, valid values range from 0 - 127, or a Tween object which defines a strategy for how to change over the course of the control change's lifetime.

    • channel: number = null

      Which channel to play the control change on, valid values range from 0 - 15, or null to allow whatever is playing the clip to decide.

    Returns Clip

  • Adds a note to the clip. The start & pitch parameters can each take arrays of values, allowing for multiple notes to be added at once for the same pitches and start beats.

    Returns

    Returns the Clip object which the note(s) is being added to.

    Parameters

    • start: number | number[]

      What beat within the clip that the note starts on. Can take array of multiple note starts

    • duration: number

      How many beats the note lasts.

    • pitch: string | number | (string | number)[]

      The MIDI pitch of the note, valid values range from 0 - 127. Can also take pitch names, see the pitch method for more information. Can take array of multiple pitch values

    • velocity: number | ITween

      The note's velocity, valid values range from 0 - 127, or a function that maps beats to values.

    • channel: number = null

      Which channel to play the note on, valid values range from 0 - 15, or null to allow whatever is playing the clip to decide.

    • ref: string = null

      Provides way of identifying notes so they can be easily retrieved later.

    Returns Clip

  • Returns true if the passed in point is greater than or equal to range start, and less than or equal to range end.

    Returns

    Parameters

    • point: number

      The point value to determine whether it's within the range.

    Returns boolean

  • Creates and returns a new deep-copy of the clip.

    Returns

    Returns Clip

  • Intended primarily for use by the ClipPlayer to fetch all pitch bends who's durations overlap with the provided start & end parameters.

    Returns

    Parameters

    • start: number

      The beat at which to start searching for overlapping pitch bends.

    • end: number

      The beat at which to end searching for overlapping pitch bends.

    Returns ClipBend[]

  • Intended primarily for use by the ClipPlayer to fetch all control changes who's durations overlap with the provided start & end parameters.

    Returns

    Parameters

    • start: number

      The beat at which to start searching for overlapping control changes.

    • end: number

      The beat at which to end searching for overlapping control changes.

    Returns ClipCC[]

  • Intended primarily for use by the ClipPlayer to fetch all notes who's end times are between the provided start & end parameters.

    Returns

    Parameters

    • start: number

      The beat at which to start searching for note endings.

    • end: number

      The beat at which to end searching for note endings.

    Returns ClipNote[]

  • Intended primarily for use by the ClipPlayer to fetch all notes who's start times are between the provided start & end parameters.

    Returns

    Parameters

    • start: number

      The beat at which to start searching for note beginnings.

    • end: number

      The beat at which to end searching for note beginnings.

    Returns ClipNote[]

  • Accepts a value and returns what percentage of the way into the range that the value is.

    The returned value can be negative, or greater than 100%, if the passed in value is less than the range start, or greater than the range end.

    Returns

    Parameters

    • value: number

      The value to compare against the range.

    Returns number

  • Reflects the clip vertically around a center pitch. Modifies the clip in place.

    Returns

    Returns the clip instance to allow for chaining.

    Parameters

    • reflectionPitch: number

      The pitch which notes in the clip are reflected around.

    Returns Clip

  • Modify the start times of notes in the clip to be closer to some desired rhythmic pattern. Modifies the clip in place.

    Returns

    Returns the clip instance to allow for chaining.

    Parameters

    • rhythm: number[]

      An array of numbers that specify a rhythm to quantize to. For example [0.5] means that the clip should be quantized to eighth notes. Alternatively, [0.5, 0.25, 0.25] means that the clip should be quantized to a heavy metal style gallop rhythm.

    • strength: number = 1

      A number from 0 to 1, 1 means full quantization to the target rhythm 0.5 will move notes half way towards the target rhythm, while 0 will do nothing

    Returns Clip

  • Reflects the clip horizontally, with events from the start reflected to the end. Modifies the clip in place.

    Returns

    Returns the clip instance to allow for chaining.

    Returns Clip

  • Used by the library for the custom serialization of Clips

    Returns { bends: ClipBend[]; controlChanges: ClipCC[]; duration: number; notes: ClipNote[]; start: number }

  • Transposes the notes in the clip up/down. Modifies the clip in place.

    Returns

    Returns the clip instance to allow for chaining.

    Parameters

    • semitones: number

      How many semitones to transpose each note in the clip up by.

    Returns Clip

  • Takes an object parsed from JSON Clip data to load into an actual clip instance.

    Parameters

    • clipData: any

    Returns Clip

Generated using TypeDoc