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

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

element to append

Source:
Returns:
Type
this

<static> Stream#appendNewCanvas(appendElement, width, height) → {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 canvas

width number | string <optional>
height number | string <optional>
Source:
Returns:

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

Type
DOMObject

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

Creates a new canvas and renders vexflow on it

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

canvas

Type
JQueryDOMObject

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

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

Calls setSubstreamRenderOptions() first.

Does not render on canvas.

Parameters:
Name Type 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()

Source:
Returns:

canvas in jquery.

Type
JQueryDOMObject

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

Creates a rendered, playable canvas where clicking plays it.

Called from appendNewCanvas() etc.

Parameters:
Name Type Description
width number | string | undefined
height number | string | undefined
Source:
Returns:

canvas

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#editableAccidentalCanvas(width, height) → {DOMObject}

Renders a stream on a canvas 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 canvas.

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(canvas, 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 canvas (canvas)

Parameters:
Name Type Description
canvas 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, $siblingCanvas) → {jQueryObject}

Parameters:
Name Type Description
minAccidental Int

alter of the min accidental (default -1)

maxAccidental Int

alter of the max accidental (default 1)

$siblingCanvas jQueryObject

canvas 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#getScaledXYforCanvas(canvas, e) → {Array.<number>}

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

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

Parameters:
Name Type Description
canvas DOMObject
e Event
Source:
Returns:

[scaledX, scaledY]

Type
Array.<number>

<static> Stream#getUnscaledXYforCanvas(canvas, e) → {Array.<number>}

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

Parameters:
Name Type Description
canvas DOMObject
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 appendCanvas 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, canvas) → {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
canvas DOMObject
Source:
Returns:

output of changedCallbackFunction

Type
any

<static> Stream#noteElementFromScaledX(xPxScaled, allowablePixels, unused_systemIndex) → {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

Parameters:
Name Type Argument Default Description
xPxScaled number
allowablePixels number <optional>
10
unused_systemIndex number <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:

Does not have functionality for stopping etc., will be removed eventually
and replaced with something better in music21.streamInteraction

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#redrawCanvas(canvas) → {music21.stream.Stream}

Redraws a canvas, keeping the events of the previous canvas.

Parameters:
Name Type Description
canvas DOMObject
Source:
Returns:

this

Type
music21.stream.Stream

<static> Stream#renderScrollableCanvas(where) → {DOMObject}

Renders a canvas which has a scrollbar when clicked.

(this is a dumb way of doing this. Expect it to disappear...)

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

canvas

Type
DOMObject

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

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

Sets canvas.storedStream to this

Runs this.setRenderInteraction on the canvas.

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

Parameters:
Name Type Description
canvas DOMObject | JQueryDOMObject

a canvas object

Source:
Returns:

this

Type
music21.stream.Stream

<static> Stream#replaceCanvas(where, preserveCanvasSize) → {JQueryDOMObject}

Replaces a particular Canvas with a new rendering of one.

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

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

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

preserveCanvasSize Boolean <optional>
false
Source:
Returns:

the canvas

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#scrollScoreStart(c, event) → {music21.streamInteraction.ScrollPlayer}

Sets up a music21.streamInteraction.ScrollPlayer for this
canvas.

Parameters:
Name Type Argument Description
c DOMObject

canvas

event Event <optional>

the event that caused the scrolling to start
(needed because event.stopPropagation() is called)

Source:
Returns:
Type
music21.streamInteraction.ScrollPlayer

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

Set the type of interaction on the canvas 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(jCanvas) → {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
jCanvas JQueryDOMObject
Source:
Returns:

this

Type
music21.stream.Stream

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

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

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