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

Variables

Const QUANTIZE_CUTOFF

QUANTIZE_CUTOFF: 0.5 = 0.5

Functions

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

assertSingleTempo

  • assertSingleTempo(ns: INoteSequence): void
  • Confirms there is no tempo change.

    Parameters

    • ns: INoteSequence

    Returns void

clone

  • clone(ns: INoteSequence): NoteSequence

getQuantizedTimeEvents

  • getQuantizedTimeEvents(ns: INoteSequence): IControlChange[]
  • Returns a list of events with a time and quantizedStep properties.

    Parameters

    • ns: INoteSequence

    Returns IControlChange[]

isAbsoluteQuantizedSequence

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

    Parameters

    • ns: INoteSequence

    Returns boolean

isPowerOf2

  • isPowerOf2(n: number): 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

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.

quantizeNotesAndEvents

  • quantizeNotesAndEvents(ns: INoteSequence, stepsPerSecond: number): void
  • Quantize the notes and events of a NoteSequence proto in place. 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.

    Parameters

    • ns: INoteSequence

      A NoteSequence to quantize. Will be modified in place.

    • stepsPerSecond: number

      Each second will be divided into this many quantized time steps.

    Returns void

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.

stepsPerQuarterToStepsPerSecond

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

    Parameters

    • stepsPerQuarter: number
    • qpm: number

    Returns number

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 wih time in seconds.

Generated using TypeDoc