new PixelMapper(s)
A PixelMapper is an object that knows how to map offsets to pixels on a flat Stream.
Helper for ScrollPlayer and soon other places...
Parameters:
| Name | Type | Description |
|---|---|---|
s |
music21.stream.Stream | stream object |
- Source:
Properties:
| Name | Type | Description |
|---|---|---|
allMaps |
Array.<music21.streamInteraction.PixelMap> | a |
s |
music21.stream.Stream | stream object |
notesAndRests |
music21.stream.Stream |
|
pixelScaling |
number |
|
startX |
number | (readonly) starting x |
maxX |
number | (readonly) ending x |
maxSystemIndex |
Int | the index of the last system. |
Methods
-
<static> PixelMapper#addNoteToMap(n) → {music21.streamInteraction.PixelMap}
-
Adds a
music21.base.Music21Object, usually amusic21.note.Noteobject,
to the maps for the PixelMapper if amusic21.streamInteraction.PixelMapobject
already exists at that location, or creates a newPixelMapif one does not exist.Parameters:
Name Type Description nmusic21.base.Music21Object note or other object
- Source:
Returns:
PixelMap added to.
-
<static> PixelMapper#findMapForExactOffset(o) → {music21.streamInteraction.PixelMap|undefined}
-
Finds a
PixelMapobject if one matches this exact offset. Otherwise returns undefinedParameters:
Name Type Description onumber offset
- Source:
Returns:
- Type
- music21.streamInteraction.PixelMap | undefined
-
<static> PixelMapper#getPixelMapsAroundOffset(offset) → {Array.<(music21.streamInteraction.PixelMap|undefined)>}
-
returns an array of two pixel maps: the previous/current one and the
next/current one (i.e., if the offset is exactly the offset of a pixel map
the prevNoteMap and nextNoteMap will be the same; similarly if the offset is
beyond the end of the score)Parameters:
Name Type Description offsetnumber - Source:
Returns:
returns two PixelMaps; or either (but not both) can be undefined
- Type
- Array.<(music21.streamInteraction.PixelMap|undefined)>
Example
var s = new music21.tinyNotation.TinyNotation('3/4 c4 d8 e f4 g4 a4 b4'); var can = s.appendNewCanvas(); var pm = new music21.streamInteraction.PixelMapper(s); var pmaps = pm.getPixelMapsAropundOffset(1.25); var prev = pmaps[0]; var next = pmaps[1]; prev.offset // 1 next.offset // 1.5 prev.x // 97... next.x // 123... -
<static> PixelMapper#getSystemIndexAtOffset(offset) → {number}
-
Uses the stored offsetToPixelMaps to get the systemIndex active at the current time.
Parameters:
Name Type Description offsetnumber - Source:
Returns:
systemIndex of the offset
- Type
- number
-
<static> PixelMapper#getXAtOffset(offset, offsetToPixelMaps) → {number}
-
Uses the stored offsetToPixelMaps to get the pixel X for the offset.
Parameters:
Name Type Description offsetnumber offsetToPixelMapsArray.<music21.streamInteraction.PixelMap> - Source:
Returns:
- Type
- number
Example
var s = new music21.tinyNotation.TinyNotation('3/4 c4 d8 e f4 g4 a4 b4'); var can = s.appendNewCanvas(); var pm = new music21.streamInteraction.PixelMapper(s); pm.getXAtOffset(0.0); // exact placement of a note // 89.94... pm.getXAtOffset(0.5); // between two notes // 138.63... -
<static> PixelMapper#processStream() → {Array.<music21.streamInteraction.PixelMap>}
-
Creates
PixelMapobjects for every note in the stream, and an extra
one mapping the end of the final offset.- Source:
Returns:
- Type
- Array.<music21.streamInteraction.PixelMap>