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.
- the highest time point in the stream's elements
- Source:
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 | |||
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 |
||
notesAndRests |
music21.stream.Stream | (readonly) like notes but also with |
||
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 |
||
autoBeam |
Boolean | whether the notes should be beamed automatically or not (will be moved to |
||
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 |
Extends
Methods
-
<static> Stream#append(el) → {this}
-
Add an element to the end of the stream, setting its
.offsetaccordinglyParameters:
Name Type Description elmusic21.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 appendElementJQueryDOMObject | DOMObject <optional>
document.body where to place the svg
widthnumber | string <optional>
heightnumber | string <optional>
elementTypestring 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 widthnumber | string | undefined <optional>
heightnumber | string | undefined <optional>
elementTypestring 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
<canvas>or<svg>object.Calls setSubstreamRenderOptions() first.
Does not render on the DOM element.
Parameters:
Name Type Default Description widthnumber | string | undefined will use
this.estimateStaffLength()+this.renderOptions.staffPaddingif not givenheightnumber | string | undefined if undefined will use
this.renderOptions.height. If still undefined, will usethis.estimateStreamHeight()elementTypestring 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 widthnumber | string | undefined heightnumber | string | undefined elementTypestring 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 yPxScalednumber - 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 widthnumber <optional>
heightnumber <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
ignoreSystemsistrue.Parameters:
Name Type Argument Default Description ignoreSystemsBoolean <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 svgDOMObject eEvent xnumber ynumber - 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 indexInt 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 minAccidentalInt alter of the min accidental (default -1)
maxAccidentalInt alter of the max accidental (default 1)
$siblingSvgjQueryObject 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 classListArray.<string> | string a list of classes to find
- Source:
Returns:
-
<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 svgDOMObject - a canvas or SVG object
eEvent - 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 xPxScalednumber <optional>
allowablePixelsnumber <optional>
10 systemIndexnumber <optional>
- Source:
Returns:
-
<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 svgDOMObject a canvas or SVG object
eEvent - 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.Voiceinside it?- Source:
Returns:
- Type
- Boolean
-
<static> Stream#insert(offset, el) → {this}
-
Add an element to the specified place in the stream, setting its
.offsetaccordinglyParameters:
Name Type Description offsetnumber offset to place.
elmusic21.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
-
<static> Stream#makeMeasures(options) → {music21.stream.Stream}
-
Takes a stream and places all of its elements into
measures (:class:~music21.stream.Measureobjects)
based on the :class:~music21.meter.TimeSignatureobjects
placed within
the stream. If no TimeSignatures are found in the
stream, a default of 4/4 is used.
Ifoptions.inPlaceis true, the original Stream is modified and lost
ifoptions.inPlaceis False, this returns a modified deep copy.Parameters:
Name Type Description optionsobject - Source:
Returns:
-
<static> Stream#noteChanged(clickedDiatonicNoteNum, foundNote, svg) → {any}
-
Change the pitch of a note given that it has been clicked and then
call changedCallbackFunctionTo be removed...
Parameters:
Name Type Description clickedDiatonicNoteNumInt foundNotemusic21.base.Music21Object svgDOMObject - 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 xPxScalednumber allowablePixelsnumber <optional>
10 systemIndexnumber <optional>
optionsobject <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)
optionscan be an object containing:- instrument:
music21.instrument.Instrumentobject (default,this.instrument) - tempo: number (default,
this.tempo)
Parameters:
Name Type Argument Description optionsobject <optional>
object of playback options
- Source:
Returns:
this
- instrument:
-
<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 svgDOMObject - Source:
Returns:
this
-
<static> Stream#renderVexflow(canvasOrSVG) → {vfShow.Renderer}
-
Uses
music21.vfShow.Rendererto render Vexflow onto an
existing canvas or SVG object.Runs
this.setRenderInteractionon the canvas.Will be moved to vfShow eventually when converter objects are enabled...maybe.
Parameters:
Name Type Description canvasOrSVGDOMObject | 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 whereJQueryDOMObject | DOMObject <optional>
the canvas or SVG to replace or a container holding the canvas(es) to replace.
preserveSvgSizeBoolean <optional>
false elementTypestring 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 theRenderOptions.eventsobject.Parameters:
Name Type Argument Default Description recursiveBoolean <optional>
false preserveEventsBoolean <optional>
false - Source:
Returns:
this
-
<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 canvasOrDivDOMObject canvas or the Div surrounding it.
- Source:
Returns:
this
-
<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
-
<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 jSvgJQueryDOMObject - Source:
Returns:
this
-
<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 eEvent - Source:
Returns:
- returns whatever changedCallbackFunction does.
- Type
- music21.base.Music21Object | undefined