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.
- 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 |
||
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 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 appendElementJQueryDOMObject | DOMObject <optional>
document.body where to place the canvas
widthnumber | string <optional>
heightnumber | 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 widthnumber | string | undefined <optional>
heightnumber | string | undefined <optional>
- Source:
Returns:
canvas
- Type
- JQueryDOMObject
-
<static> Stream#createNewCanvas(width, height) → {JQueryDOMObject}
-
Creates and returns a new
<canvas>object.Calls setSubstreamRenderOptions() first.
Does not render on canvas.
Parameters:
Name Type 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()- 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 widthnumber | string | undefined heightnumber | 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 yPxScalednumber - 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 widthnumber <optional>
heightnumber <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
ignoreSystemsistrue.Parameters:
Name Type Argument Default Description ignoreSystemsBoolean <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 canvasDOMObject 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, $siblingCanvas) → {jQueryObject}
-
Parameters:
Name Type Description minAccidentalInt alter of the min accidental (default -1)
maxAccidentalInt alter of the max accidental (default 1)
$siblingCanvasjQueryObject 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 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#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 canvasDOMObject eEvent - 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 canvasDOMObject 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 appendCanvas 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, canvas) → {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 canvasDOMObject - 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 xPxScalednumber allowablePixelsnumber <optional>
10 unused_systemIndexnumber <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)
Does not have functionality for stopping etc., will be removed eventually
and replaced with something better inmusic21.streamInteractionParameters:
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#redrawCanvas(canvas) → {music21.stream.Stream}
-
Redraws a canvas, keeping the events of the previous canvas.
Parameters:
Name Type Description canvasDOMObject - Source:
Returns:
this
-
<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 whereJQueryDOMObject | DOMObject <optional>
- Source:
Returns:
canvas
- Type
- DOMObject
-
<static> Stream#renderVexflowOnCanvas(canvas) → {music21.stream.Stream}
-
Uses
music21.vfShow.Rendererto render Vexflow onto an
existing canvas object.Sets canvas.storedStream to this
Runs
this.setRenderInteractionon the canvas.Will be moved to vfShow eventually when converter objects are enabled...maybe.
Parameters:
Name Type Description canvasDOMObject | JQueryDOMObject a canvas object
- Source:
Returns:
this
-
<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 whereJQueryDOMObject | DOMObject <optional>
the canvas to replace or a container holding the canvas(es) to replace.
preserveCanvasSizeBoolean <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 theRenderOptions.eventsobject.Parameters:
Name Type Argument Default Description recursiveBoolean <optional>
false preserveEventsBoolean <optional>
false - Source:
Returns:
this
-
<static> Stream#scrollScoreStart(c, event) → {music21.streamInteraction.ScrollPlayer}
-
Sets up a
music21.streamInteraction.ScrollPlayerfor this
canvas.Parameters:
Name Type Argument Description cDOMObject canvas
eventEvent <optional>
the event that caused the scrolling to start
(needed becauseevent.stopPropagation()is called)- Source:
Returns:
-
<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 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(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 jCanvasJQueryDOMObject - Source:
Returns:
this
-
<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 eEvent - Source:
Returns:
- returns whatever changedCallbackFunction does.
- Type
- music21.base.Music21Object | undefined