Class: Stream

music21.stream. Stream

new Stream()

A generic Stream class -- a holder for other music21 objects
Will be subclassed into music21.stream.Score,
music21.stream.Part,
music21.stream.Measure,
music21.stream.Voice, but most functions will be found here.

Properties:
Name Type Argument Default Description
elements Array.<music21.base.Music21Object>

the elements in the stream. DO NOT MODIFY individual components (consider it like a Python tuple)

length Int

(readonly) the number of elements in the stream.

duration music21.duration.Duration

the total duration of the stream's elements

highestTime number
  • the highest time point in the stream's elements
clef music21.clef.Clef

the clef for the Stream (if there is one; if there are multiple, then the first clef)

timeSignature music21.meter.TimeSignature

the first TimeSignature of the Stream

keySignature music21.key.KeySignature

the first KeySignature for the Stream

renderOptions music21.renderOptions.RenderOptions

an object specifying how to render the stream

flat music21.stream.Stream

(readonly) a flattened representation of the Stream

notes music21.stream.Stream

(readonly) the stream with only music21.note.Note and music21.chord.Chord objects included

notesAndRests music21.stream.Stream

(readonly) like notes but also with music21.note.Rest objects included

parts music21.stream.Stream

(readonly) a filter on the Stream to just get the parts (NON-recursive)

measures music21.stream.Stream

(readonly) a filter on the Stream to just get the measures (NON-recursive)

tempo number

tempo in beats per minute (will become more sophisticated later, but for now the whole stream has one tempo

instrument music21.instrument.Instrument | undefined

an instrument object associated with the stream (can be set with a string also, but will return an Instrument object)

autoBeam Boolean

whether the notes should be beamed automatically or not (will be moved to renderOptions soon)

staffLines Int <optional>
5

number of staff lines

changedCallbackFunction function | undefined

function to call when the Stream changes through a standard interface

maxSystemWidth number

confusing... should be in renderOptions

Source:

Extends

Methods

<static> Stream#append(el) → {this}

Add an element to the end of the stream, setting its .offset accordingly

Parameters:
Name Type Description
el music21.base.Music21Object | Array

element or list of elements to append

Source:
Returns:
Type
this

<static> Stream#appendNewDOM(appendElement, width, height, elementType) → {DOMObject}

Creates a new canvas, renders vexflow on it, and appends it to the DOM.

Parameters:
Name Type Argument Default Description
appendElement JQueryDOMObject | DOMObject <optional>
document.body

where to place the svg

width number | string <optional>
height number | string <optional>
elementType string svg

what type of element, default = svg

Source:
Returns:

svg (not the jQueryDOMObject -- this is a difference with other routines and should be fixed. TODO: FIX)

Type
DOMObject

<static> Stream#createDOM(width, height, elementType) → {JQueryDOMObject}

Creates a new svg and renders vexflow on it

Parameters:
Name Type Argument Default Description
width number | string | undefined <optional>
height number | string | undefined <optional>
elementType string svg

what type of element svg or canvas, default = svg

Source:
Returns:

canvas or SVG

Type
JQueryDOMObject

<static> Stream#createNewDOM(width, height, elementType) → {JQueryDOMObject}

Creates and returns a new &lt;canvas&gt; or &lt;svg&gt; object.

Calls setSubstreamRenderOptions() first.

Does not render on the DOM element.

Parameters:
Name Type Default Description
width number | string | undefined

will use this.estimateStaffLength() + this.renderOptions.staffPadding if not given

height number | string | undefined

if undefined will use this.renderOptions.height. If still undefined, will use this.estimateStreamHeight()

elementType string svg

what type of element, default = svg

Source:
Returns:

svg in jquery.

Type
JQueryDOMObject

<static> Stream#createPlayableDOM(width, height, elementType) → {JQueryDOMObject}

Creates a rendered, playable svg where clicking plays it.

Called from appendNewDOM() etc.

Parameters:
Name Type Default Description
width number | string | undefined
height number | string | undefined
elementType string svg

what type of element, default = svg

Source:
Returns:

canvas or svg

Type
JQueryDOMObject

<static> Stream#diatonicNoteNumFromScaledY(yPxScaled) → {Int}

Given a Y position find the diatonicNoteNum that a note at that position would have.

searches this.storedVexflowStave

Y position must be offset from the start of the stave...

Parameters:
Name Type Description
yPxScaled number
Source:
Returns:
Type
Int

<static> Stream#editableAccidentalDOM(width, height) → {DOMObject}

Renders a stream on svg with the ability to edit it and
a toolbar that allows the accidentals to be edited.

Parameters:
Name Type Argument Description
width number <optional>
height number <optional>
Source:
Returns:

<div> tag around the svg.

Type
DOMObject

<static> Stream#estimateStaffLength() → {number}

Estimates the length of the Stream in pixels.

Source:
Returns:

length in pixels

Type
number

<static> Stream#estimateStreamHeight(ignoreSystems) → {number}

Estimate the stream height for the Stream.

If there are systems they will be incorporated into the height unless ignoreSystems is true.

Parameters:
Name Type Argument Default Description
ignoreSystems Boolean <optional>
false
Source:
Returns:

height in pixels

Type
number

<static> Stream#findNoteForClick(svg, e, x, y) → {Array}

Given an event object, and an x and y location, returns a two-element array
of the pitch.Pitch.diatonicNoteNum that was clicked (i.e., if C4 was clicked this
will return 29; if D4 was clicked this will return 30) and the closest note in the
stream that was clicked.

Return a list of [diatonicNoteNum, closestXNote]
for an event (e) called on the svg (svg)

Parameters:
Name Type Description
svg DOMObject
e Event
x number
y number
Source:
Returns:

[diatonicNoteNum, closestXNote]

Type
Array

<static> Stream#get(index) → {music21.base.Music21Object|undefined}

Get the indexth element from the Stream. Equivalent to the
music21p format of s[index]. Can use negative indexing to get from the end.

Parameters:
Name Type Description
index Int

can be -1, -2, to index from the end, like python

Source:
Returns:
Type
music21.base.Music21Object | undefined

<static> Stream#getAccidentalToolbar(minAccidental, maxAccidental, $siblingSvg) → {jQueryObject}

Parameters:
Name Type Description
minAccidental Int

alter of the min accidental (default -1)

maxAccidental Int

alter of the max accidental (default 1)

$siblingSvg jQueryObject

svg to use for redrawing;

Source:
Returns:

the accidental toolbar.

Type
jQueryObject

<static> Stream#getElementsByClass(classList) → {music21.stream.Stream}

Find all elements with a certain class; if an Array is given, then any
matching class will work.

Parameters:
Name Type Description
classList Array.<string> | string

a list of classes to find

Source:
Returns:
Type
music21.stream.Stream

<static> Stream#getPlayToolbar() → {jQueryObject}

Source:
Returns:

a Div containing two buttons -- play and stop

Type
jQueryObject

<static> Stream#getScaledXYforDOM(svg, e) → {Array.<number>}

return a list of [scaledX, scaledY] for
a svg element.

xScaled refers to 1/scaleFactor.x -- for instance, scaleFactor.x = 0.7 (default)
x of 1 gives 1.42857...

Parameters:
Name Type Description
svg DOMObject
  • a canvas or SVG object
e Event
Source:
Returns:

[scaledX, scaledY]

Type
Array.<number>

<static> Stream#getStreamFromScaledXandSystemIndex(xPxScaled, allowablePixels, systemIndex) → {music21.stream.Stream}

Returns the stream that is at X location xPxScaled and system systemIndex.

Override in subclasses, always returns this; here.

Parameters:
Name Type Argument Default Description
xPxScaled number <optional>
allowablePixels number <optional>
10
systemIndex number <optional>
Source:
Returns:
Type
music21.stream.Stream

<static> Stream#getUnscaledXYforDOM(svg, e) → {Array.<number>}

Given a mouse click, or other event with .pageX and .pageY,
find the x and y for the svg.

Parameters:
Name Type Description
svg DOMObject

a canvas or SVG object

e Event
Source:
Returns:

two-elements, [x, y] in pixels.

Type
Array.<number>

<static> Stream#hasLyrics() → {Boolean}

Returns true if any note in the stream has lyrics, otherwise false

Source:
Returns:
Type
Boolean

<static> Stream#hasSubStreams() → {Boolean}

Returns Boolean about whether this stream contains any other streams.

Source:
Returns:
Type
Boolean

<static> Stream#hasVoices() → {Boolean}

Does this stream have a music21.stream.Voice inside it?

Source:
Returns:
Type
Boolean

<static> Stream#insert(offset, el) → {this}

Add an element to the specified place in the stream, setting its .offset accordingly

Parameters:
Name Type Description
offset number

offset to place.

el music21.base.Music21Object

element to append

Source:
Returns:
Type
this

<static> Stream#makeAccidentals() → {music21.stream.Stream}

Sets Pitch.accidental.displayStatus for every element with a
pitch or pitches in the stream. If a natural needs to be displayed
and the Pitch does not have an accidental object yet, adds one.

Called automatically before appendDOM routines are called.

Source:
Returns:

this

Type
music21.stream.Stream

<static> Stream#makeMeasures(options) → {music21.stream.Stream}

Takes a stream and places all of its elements into
measures (:class:~music21.stream.Measure objects)
based on the :class:~music21.meter.TimeSignature objects
placed within
the stream. If no TimeSignatures are found in the
stream, a default of 4/4 is used.
If options.inPlace is true, the original Stream is modified and lost
if options.inPlace is False, this returns a modified deep copy.

Parameters:
Name Type Description
options object
Source:
Returns:
Type
music21.stream.Stream

<static> Stream#noteChanged(clickedDiatonicNoteNum, foundNote, svg) → {any}

Change the pitch of a note given that it has been clicked and then
call changedCallbackFunction

To be removed...

Parameters:
Name Type Description
clickedDiatonicNoteNum Int
foundNote music21.base.Music21Object
svg DOMObject
Source:
Returns:

output of changedCallbackFunction

Type
any

<static> Stream#noteElementFromScaledX(xPxScaled, allowablePixels, systemIndex, options) → {music21.base.Music21Object|undefined}

Return the note at pixel X (or within allowablePixels [default 10])
of the note.

systemIndex element is not used on bare Stream

options can be a dictionary of: 'allowBackup' which gets the closest
note within the window even if it's beyond allowablePixels (default: true)
and 'backupMaximum' which specifies a maximum distance even for backup
(default: 70);

Parameters:
Name Type Argument Default Description
xPxScaled number
allowablePixels number <optional>
10
systemIndex number <optional>
options object <optional>
Source:
Returns:
Type
music21.base.Music21Object | undefined

<static> Stream#offsetMap()

Returns a list of OffsetMap objects

Source:
Returns:

[music21.stream.OffsetMap]

<static> Stream#playStream(options) → {music21.stream.Stream}

Plays the Stream through the MIDI/sound playback (for now, only MIDI.js is supported)

options can be an object containing:

Parameters:
Name Type Argument Description
options object <optional>

object of playback options

Source:
Returns:

this

Type
music21.stream.Stream

<static> Stream#pop() → {music21.base.Music21Object|undefined}

Remove and return the last element in the stream,
or return undefined if the stream is empty

Source:
Returns:

last element in the stream

Type
music21.base.Music21Object | undefined

<static> Stream#recursiveGetStoredVexflowStave() → {Vex.Flow.Stave|undefined}

Recursively search downward for the closest storedVexflowStave...

Source:
Returns:
Type
Vex.Flow.Stave | undefined

<static> Stream#redrawDOM(svg) → {music21.stream.Stream}

Redraws an svgDiv, keeping the events of the previous svg.

Parameters:
Name Type Description
svg DOMObject
Source:
Returns:

this

Type
music21.stream.Stream

<static> Stream#renderVexflow(canvasOrSVG) → {vfShow.Renderer}

Uses music21.vfShow.Renderer to render Vexflow onto an
existing canvas or SVG object.

Runs this.setRenderInteraction on the canvas.

Will be moved to vfShow eventually when converter objects are enabled...maybe.

Parameters:
Name Type Description
canvasOrSVG DOMObject | JQueryDOMObject

a canvas or the div surrounding an SVG object

Source:
Returns:
Type
vfShow.Renderer

<static> Stream#replaceDOM(where, preserveSvgSize, elementType) → {JQueryDOMObject}

Replaces a particular Svg with a new rendering of one.

Note that if 'where' is empty, will replace all svges on the page.

Parameters:
Name Type Argument Default Description
where JQueryDOMObject | DOMObject <optional>

the canvas or SVG to replace or a container holding the canvas(es) to replace.

preserveSvgSize Boolean <optional>
false
elementType string svg

what type of element, default = svg

Source:
Returns:

the svg

Type
JQueryDOMObject

<static> Stream#resetRenderOptions(recursive, preserveEvents) → {music21.stream.Stream}

Resets all the RenderOptions back to defaults. Can run recursively
and can also preserve the RenderOptions.events object.

Parameters:
Name Type Argument Default Description
recursive Boolean <optional>
false
preserveEvents Boolean <optional>
false
Source:
Returns:

this

Type
music21.stream.Stream

<static> Stream#setRenderInteraction(canvasOrDiv) → {music21.stream.Stream}

Set the type of interaction on the svg based on

  • Stream.renderOptions.events.click
  • Stream.renderOptions.events.dblclick
  • Stream.renderOptions.events.resize

Currently the only options available for each are:

  • 'play' (string)
  • 'reflow' (string; only on event.resize)
  • customFunction (will receive event as a first variable; should set up a way to
              find the original stream; var s = this; var f = function () { s...}
             )
Parameters:
Name Type Description
canvasOrDiv DOMObject

canvas or the Div surrounding it.

Source:
Returns:

this

Type
music21.stream.Stream

<static> Stream#setSubstreamRenderOptions() → {music21.stream.Stream}

Sets the render options for any substreams (such as placing them
in systems, etc.) DOES NOTHING for music21.stream.Stream, but is
overridden in subclasses.

Source:
Returns:

this

Type
music21.stream.Stream

<static> Stream#stopPlayStream() → {musci21.stream.Stream}

Stops a stream from playing if it currently is.

Source:
Returns:

this

Type
musci21.stream.Stream

<static> Stream#windowReflowStart(jSvg) → {music21.stream.Stream}

Begins a series of bound events to the window that makes it
so that on resizing the stream is redrawn and reflowed to the
new size.

Parameters:
Name Type Description
jSvg JQueryDOMObject
Source:
Returns:

this

Type
music21.stream.Stream

<static> this.DOMChangerFunction(e) → {music21.base.Music21Object|undefined}

A function bound to the current stream that
will changes the stream. Used in editableAccidentalDOM, among other places.

 var can = s.appendNewDOM();
 $(can).on('click', s.DOMChangerFunction);
Parameters:
Name Type Description
e Event
Source:
Returns:
  • returns whatever changedCallbackFunction does.
Type
music21.base.Music21Object | undefined
Music21j, Copyright © 2013-2018 Michael Scott Cuthbert and cuthbertLab.
Documentation generated by JSDoc 3.5.5 on Wed Jul 4th 2018 using the DocStrap template.