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

concatenate

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

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

    Returns NoteSequence

concatenateHelper

  • concatenateHelper(seqs: INoteSequence[], totalKey: "totalQuantizedSteps" | "totalTime", startKey: "startTime" | "quantizedStartStep", endKey: "endTime" | "quantizedEndStep", sequenceDurations?: number[]): NoteSequence
  • Parameters

    • seqs: INoteSequence[]
    • totalKey: "totalQuantizedSteps" | "totalTime"
    • startKey: "startTime" | "quantizedStartStep"
    • endKey: "endTime" | "quantizedEndStep"
    • Optional sequenceDurations: number[]

    Returns 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

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.

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.

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 an unquantized 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.

trimHelper

  • trimHelper(ns: INoteSequence, start: number, end: number, totalKey: "totalQuantizedSteps" | "totalTime", startKey: "startTime" | "quantizedStartStep", endKey: "endTime" | "quantizedEndStep", truncateEndNotes?: boolean): NoteSequence
  • Parameters

    • ns: INoteSequence
    • start: number
    • end: number
    • totalKey: "totalQuantizedSteps" | "totalTime"
    • startKey: "startTime" | "quantizedStartStep"
    • endKey: "endTime" | "quantizedEndStep"
    • Optional truncateEndNotes: boolean

    Returns NoteSequence

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