Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "core/sequences"

A library for common manipulations of NoteSequences.

license

Copyright 2018 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Functions

applySustainControlChanges

  • applySustainControlChanges(noteSequence: INoteSequence, sustainControlNumber?: number): NoteSequence
  • Create a new NoteSequence with sustain pedal control changes applied.

    Extends each note within a sustain to either the beginning of the next note of the same pitch or the end of the sustain period, whichever happens first. This is done on a per instrument basis, so notes are only affected by sustain events for the same instrument. Drum notes will not be modified.

    throws

    {Error}: If note_sequence is quantized. Sustain can only be applied to unquantized note sequences.

    Parameters

    • noteSequence: INoteSequence

      The NoteSequence for which to apply sustain. This object will not be modified.

    • Default value sustainControlNumber: number = 64

      The MIDI control number for sustain pedal. Control events with this number and value 0-63 will be treated as sustain pedal OFF events, and control events with this number and value 64-127 will be treated as sustain pedal ON events.

    Returns NoteSequence

    A copy of note_sequence but with note end times extended to account for sustain.

assertIsAbsoluteQuantizedSequence

  • assertIsAbsoluteQuantizedSequence(ns: INoteSequence): void
  • Confirms that the given NoteSequence has been quantized by absolute time.

    Parameters

    • ns: INoteSequence

    Returns void

assertIsQuantizedSequence

  • assertIsQuantizedSequence(ns: INoteSequence): void
  • Confirms that the given NoteSequence has been quantized.

    Parameters

    • ns: INoteSequence

    Returns void

assertIsRelativeQuantizedSequence

  • assertIsRelativeQuantizedSequence(ns: INoteSequence): void
  • Confirms that the given NoteSequence has been quantized relative to tempo.

    Parameters

    • ns: INoteSequence

    Returns void

clone

  • clone(ns: INoteSequence): NoteSequence

concatenate

  • concatenate(concatenateSequences: INoteSequence[], sequenceDurations?: number[]): NoteSequence
  • Parameters

    • concatenateSequences: INoteSequence[]
    • Optional sequenceDurations: number[]

    Returns NoteSequence

createQuantizedNoteSequence

  • createQuantizedNoteSequence(stepsPerQuarter?: number, qpm?: number): NoteSequence
  • Create an empty quantized NoteSequence with steps per quarter note and tempo.

    Parameters

    • Default value stepsPerQuarter: number = constants.DEFAULT_STEPS_PER_QUARTER

      The number of steps per quarter note to use.

    • Default value qpm: number = constants.DEFAULT_QUARTERS_PER_MINUTE

      The tempo to use.

    Returns NoteSequence

    A new quantized NoteSequence.

isAbsoluteQuantizedSequence

  • isAbsoluteQuantizedSequence(ns: INoteSequence): boolean
  • Returns whether the given NoteSequence has been quantized by absolute time.

    Parameters

    • ns: INoteSequence

    Returns boolean

isQuantizedSequence

  • isQuantizedSequence(ns: INoteSequence): boolean
  • Returns whether or not a NoteSequence proto has been quantized.

    Parameters

    • ns: INoteSequence

    Returns boolean

isRelativeQuantizedSequence

  • isRelativeQuantizedSequence(ns: INoteSequence): boolean
  • Returns whether the given NoteSequence has been quantized relative to tempo.

    Parameters

    • ns: INoteSequence

    Returns boolean

mergeConsecutiveNotes

  • mergeConsecutiveNotes(sequence: INoteSequence): NoteSequence
  • Any consecutive notes of the same pitch are merged into a sustained note. Does not merge notes that connect on a measure boundary. This process also rearranges the order of the notes - notes are grouped by instrument, then ordered by timestamp.

    Parameters

    • sequence: INoteSequence

      A quantized NoteSequence to be merged.

    Returns NoteSequence

    a new NoteSequence with sustained notes merged.

mergeInstruments

  • mergeInstruments(ns: INoteSequence): NoteSequence
  • Assign instruments to the notes, pitch bends, and control changes of a NoteSequence based on program numbers and drum status. All drums will be assigned the last instrument (and program 0). All non-drum events with the same program number will be assigned to a single instrument.

    Parameters

    • ns: INoteSequence

      The NoteSequence for which to merge instruments. Will not be modified.

    Returns NoteSequence

    A copy of ns with merged instruments.

quantizeNoteSequence

  • quantizeNoteSequence(ns: INoteSequence, stepsPerQuarter: number): NoteSequence
  • Quantize a NoteSequence proto relative to tempo.

    The input NoteSequence is copied and quantization-related fields are populated. Sets the steps_per_quarter field in the quantization_info message in the NoteSequence.

    Note start and end times, and chord times are snapped to a nearby quantized step, and the resulting times are stored in a separate field (e.g., QuantizedStartStep). See the comments above QUANTIZE_CUTOFF for details on how the quantizing algorithm works.

    throws

    {MultipleTempoException} If there is a change in tempo in the sequence.

    throws

    {MultipleTimeSignatureException} If there is a change in time signature in the sequence.

    throws

    {BadTimeSignatureException} If the time signature found in the sequence has a 0 numerator or a denominator which is not a power of 2.

    throws

    {NegativeTimeException} If a note or chord occurs at a negative time.

    Parameters

    • ns: INoteSequence

      The NoteSequence to quantize.

    • stepsPerQuarter: number

      Each quarter note of music will be divided into this many quantized time steps.

    Returns NoteSequence

    A copy of the original NoteSequence, with quantized times added.

quantizeToStep

  • quantizeToStep(unquantizedSeconds: number, stepsPerSecond: number, quantizeCutoff?: number): number
  • Quantizes seconds to the nearest step, given steps_per_second. See the comments above QUANTIZE_CUTOFF for details on how the quantizing algorithm works.

    Parameters

    • unquantizedSeconds: number

      Seconds to quantize.

    • stepsPerSecond: number

      Quantizing resolution.

    • Default value quantizeCutoff: number = QUANTIZE_CUTOFF

      Value to use for quantizing cutoff.

    Returns number

    the quantized step.

replaceInstruments

  • replaceInstruments(originalSequence: INoteSequence, replaceSequence: INoteSequence): NoteSequence
  • Replaces all the notes in an input sequence that match the instruments in a second sequence. For example, if replaceSequence has notes that all have either instrument=0 or instrument=1, then any notes in originalSequence with instruments 0 or 1 will be removed and replaced with the notes in replaceSequence. If there are instruments in replaceSequence that are not in originalSequence, they will not be added.

    Parameters

    • originalSequence: INoteSequence

      The NoteSequence to be changed.

    • replaceSequence: INoteSequence

      The NoteSequence that will replace the notes in sequence with the same instrument.

    Returns NoteSequence

    a new NoteSequence with the instruments replaced.

split

  • split(seq: INoteSequence, chunkSize: number): NoteSequence[]
  • Splits a quantized NoteSequence into smaller NoteSequences of equal chunks. If a note splits across a chunk boundary, then it will be split between the two chunks.

    Silent padding may be added to the final chunk to make it chunkSize.

    Parameters

    • seq: INoteSequence
    • chunkSize: number

      The number of steps per chunk. For example, if you want to split the sequence into 2 bar chunks, then if the sequence has 4 steps/quarter, that will be 32 steps for each 2 bars (so a chunkSize of 32).

    Returns NoteSequence[]

    An array of NoteSequences each of which are at most chunkSize steps.

stepsPerQuarterToStepsPerSecond

  • stepsPerQuarterToStepsPerSecond(stepsPerQuarter: number, qpm: number): number
  • Calculates steps per second given stepsPerQuarter and a QPM.

    Parameters

    • stepsPerQuarter: number
    • qpm: number

    Returns number

trim

  • trim(ns: INoteSequence, start: number, end: number, truncateEndNotes?: boolean): NoteSequence
  • Trim notes from a NoteSequence to lie within a specified time range. Notes starting before start are not included. Notes ending after end are not included, unless truncateEndNotes is true.

    Parameters

    • ns: INoteSequence

      The NoteSequence for which to trim notes.

    • start: number

      The time after which all notes should begin. This should be either seconds (if ns is unquantized), or a quantized step (if ns is quantized).

    • end: number

      The time before which all notes should end. This should be either seconds (if ns is unquantized), or a quantized step (if ns is quantized).

    • Optional truncateEndNotes: boolean

      Optional. If true, then notes starting before the end time but ending after it will be included and truncated.

    Returns NoteSequence

    A new NoteSequence with all notes trimmed to lie between start and end, and time-shifted to begin at 0.

unquantizeSequence

  • unquantizeSequence(qns: INoteSequence, qpm?: number): NoteSequence
  • Create an unquantized version of a quantized NoteSequence.

    Any existing times will be replaced in the output NoteSequence and quantization info and steps will be removed.

    Parameters

    • qns: INoteSequence
    • Optional qpm: number

      The tempo to use. If not provided, the tempo in ns is used, or the default of 120 if it is not specified in the sequence either.

    Returns NoteSequence

    a new non-quantized NoteSequence with time in seconds.

Generated using TypeDoc