Index intervals. Use the IntervalIndexer to find vertical (harmonic) intervals between two parts. Use the HorizontalIntervalIndexer to find horizontal (melodic) intervals in the same part.
Bases: vis.analyzers.indexers.interval.IntervalIndexer
Use music21.interval.Interval to create an index of the horizontal (melodic) intervals in a single part.
You should provide the result of NoteRestIndexer.
The output format is described in run().
Parameters: |
|
---|
Make a new index of the piece.
Returns: | A list of the new indices. The index of each Series corresponds to the index it has in the list of Series given to the constructor. |
---|---|
Return type: | list of pandas.Series |
Bases: vis.analyzers.indexer.Indexer
Use music21.interval.Interval to create an index of the vertical (harmonic) intervals between two-part combinations.
You should provide the result of NoteRestIndexer.
The output format is described in run().
Parameters: |
|
---|
A dict of default settings for the IntervalIndexer.
A list of possible settings for the IntervalIndexer.
Parameters: |
|
---|
The IntervalIndexer requires a list of Series as input. These should be the result of NoteRestIndexer.
alias of Series
Make a new index of the piece.
Returns: | A dictionary of the new interval indices. Find part combinations by using the index of the parts as provided to the __init__() method, set as a string with a comma. Refer to the “Example” below. |
---|---|
Return type: | dict of pandas.Series |
** Example **
To access the intervals between the two highest parts in a score:
>>> result = an_interval_indexer.run()
>>> result['0,1']
Series([], type: object) # whatever intervals
Used internally by the IntervalIndexer and HorizontalIntervalIndexer.
Call real_indexer() with settings to print compound intervals without quality.
Used internally by the IntervalIndexer and HorizontalIntervalIndexer.
Call real_indexer() with settings to print simple intervals without quality.
Used internally by the IntervalIndexer and HorizontalIntervalIndexer.
Call real_indexer() with settings to print compound intervals with quality.
Used internally by the IntervalIndexer and HorizontalIntervalIndexer.
Call real_indexer() with settings to print simple intervals with quality.
Transforms a key in the results of IntervalIndexer.run() into a 2-tuple with the indices of the parts held therein.
Parameters: | key (unicode string) – The key from IntervalIndexer. |
---|---|
Returns: | The indices of parts referred to by the key. |
Return type: | tuple of int |
>>> key_to_tuple(u'5,6')
(5, 6)
>>> key_to_tuple(u'234522,98100')
(234522, 98100)
>>> var = key_to_tuple(u'1,2')
>>> key_to_tuple(str(var[0]) + u',' + str(var[1]))
(1, 2)
Used internally by the IntervalIndexer and HorizontalIntervalIndexer.
Turn a notes-and-rests simultaneity into the name of the interval it represents. Note that, because of the ``u’Rest’` strings, you can compare the duration of the piece in which the two parts do or do not have notes sounding together.
Parameters: |
|
---|
Returns: | u'Rest' if one or more of the parts is u'Rest'; otherwise, the interval between parts. |
---|---|
Return type: | unicode string |
Indexer to find k-part any-object n-grams.
Bases: vis.analyzers.indexer.Indexer
Indexer that finds k-part n-grams from other indices.
The indexer requires at least one “vertical” index, and supports “horizontal” indices that seem to “connect” instances in the vertical indices. Although we use “vertical” and “horizontal” to describe these index types, because the class is an abstraction of two-part interval n-grams, you can supply any information as either type of index. If you want one-part melodic n-grams for example, you should supply the relevant interval information as the “vertical” component.
There is no relationship between the number of index types, though there must be at least one “vertical” index.
The settings given to __init__() specify which index values in score are horizontal or vertical intervals. They will be added in the n-gram in the order specified, so if the u'vertical' setting is [4, 1, 3] for lists of intervals, then for each vertical event, objects will be listed in that order.
In the output, groups of “vertical” events are enclosed in brackets, while groups of “horizontal” events are enclosed in parentheses.
For cases where there is only one index in a particular direction, you can avoid printing the brackets or parentheses by setting the u'mark singles' setting to False (though the default is True).
If you want n-grams to terminate when finding one or several particular values, you can specify this with the u'terminator' setting.
To show that a horizontal event continues, we use u'_' by default, but you can set this separately, for example to u'P1' u'0', as seems appropriate.
You can also use the NGramIndexer to collect “stacks” of single vertical events. If you provide indices of intervals above a lowest part, for example, these “stacks” become the figured bass signature of a single moment. Set u'n' to 1 for this feature. Horizontal events are obviously ignored.
Parameters: |
|
---|---|
Raises: | RuntimeError if score is the wrong type. |
Raises: | RuntimeError if score is not a list of the same types. |
Raises: | RuntimeError if required settings are not present in settings. |
Raises: | RuntimeError if u'n' is less than 1. |
A dict of default settings for the NGramIndexer.
A list of possible settings for the NGramIndexer.
Parameters: |
|
---|
The NGramIndexer requires pandas.Series as input.
alias of Series
Make an index of k-part n-grams of anything.
Returns: | A single-item list with the new index. |
---|---|
Return type: | list of pandas.Series |
Index note and rest objects.
Bases: vis.analyzers.indexer.Indexer
Index music21.note.Note and Rest objects found in a music21.stream.Part.
Rest objects are indexed as u'Rest', and Note objects as the unicode-format version of their pitchWithOctave attribute.
Parameters: |
|
---|---|
Raises: | RuntimeError if score is not a list of the right type. |
The NoteRestIndexer uses Part objects directly.
alias of Part
Make a new index of the piece.
Returns: | A list of the new indices. The index of each Series corresponds to the index of the Part used to generate it, in the order specified to the constructor. Each element in the Series is a unicode. |
---|---|
Return type: | list of pandas.Series |
Used internally by NoteRestIndexer. Convert objects from the music21.note module into a unicode.
Parameters: | obj (list of music21.note.Note or music21.note.Rest) – A list with the object to convert. |
---|
Returns: | If the first object in the list is a music21.note.Rest, the string u'Rest'; otherwise the nameWithOctave attribute, which is the pitch class and octave of the music21.note.Note. |
---|---|
Return type: | unicode |
Indexers that modify the “offset” values (floats stored as the “index” of a pandas.Series), potentially adding repetitions of or removing pre-existing events, without modifying the events themselves.
Bases: vis.analyzers.indexer.Indexer
Indexer that regularizes the “offset” values of observations from other indexers.
The Indexer regularizes observations from offsets spaced any, possibly irregular, quarterLength durations apart, so they are instead observed at regular intervals. This has two effects:
Since elements’ durations are not recorded, the last observation in a Series will always be included in the results. If it does not start on an observed offset, it will be included as the next observed offset—again, whether or not this is true in the actual music. However, the last observation will only ever be counted once, even if a part ends before others in a piece with many parts. See the doctests for examples.
Examples. For all, the quarterLength is 1.0.
When events in the input already appear at intervals of quarterLength, input and output are identical.
offset | 0.0 | 1.0 | 2.0 |
---|---|---|---|
input | a | b | c |
output | a | b | c |
When events in the input appear at intervals of quarterLength, but there are additional elements between the observed offsets, those additional elements are removed.
offset | 0.0 | 0.5 | 1.0 | 2.0 |
---|---|---|---|---|
input | a | A | b | c |
output | a | b | c |
offset | 0.0 | 0.25 | 0.5 | 1.0 | 2.0 |
---|---|---|---|---|---|
input | a | z | A | b | c |
output | a | b | c |
When events in the input appear at intervals of quarterLength, but not at every observed offset, the event from the previous offset is repeated.
offset | 0.0 | 1.0 | 2.0 |
---|---|---|---|
input | a | c | |
output | a | a | c |
When events in the input appear at offsets other than those observed by the specified quarterLength, the “most recent” event will appear.
offset | 0.0 | 0.25 | 0.5 | 1.0 | 2.0 |
---|---|---|---|---|---|
input | a | z | A | c | |
output | a | A | c |
When the final event does not appear at an observed offset, it will be included in the output at the next offset that would be observed, even if this offset does not appear in the score file to which the results correspond.
offset | 0.0 | 1.0 | 1.5 | 2.0 |
---|---|---|---|---|
input | a | b | d | |
output | a | b | d |
The behaviour in this last example can create a potentially misleading result for some analytic situations that consider metre. It avoids another potentially misleading situation where the final chord of a piece would appear to be dissonant because of a suspension. We chose to lose metric and rythmic precision, which would be more profitably analyzed with indexers built for that purpose. Consider this illustration, where the numbers correspond to scale degrees.
offset | 410.0 | 411.0 | 411.5 | 412.0 |
---|---|---|---|---|
in-S | 2 | 1 | ||
in-A | 7— | 6 | 1 | |
in-T | 4 | 3 | ||
in-B | 5 | 1 | ||
out-S | 2 | 1 | 1 | |
out-A | 7— | 7 | 1 | |
out-T | 4 | 3 | 3 | |
out-B | 5 | 1 | 1 |
If we left out the note event appear in the in-A part at offset 411.5, the piece would appear to end with a dissonant sonority!
Parameters: |
|
---|---|
Raises: | RuntimeError if score is the wrong type. |
Raises: | RuntimeError if score is not a list of the same types. |
Raises: | RuntimeError if the required setting is not present in settings. |
Raises: | RuntimeError if the u'quarterLength' setting has a value less than 0.001. |
A list of possible settings for the FilterByOffsetIndexer.
Parameters: | u’quarterLength’ (float) – The quarterLength duration between observations desired in the output. This value must not have more than three digits to the right of the decimal (i.e. 0.001 is the smallest possible value). |
---|
The FilterByOffsetIndexer uses pandas.Series objects.
alias of Series
Regularize the observed offsets for the inputted Series.
Returns: | A DataFrame with the indices for all the inputted parts, where the “index” value for each part is the same as in the list in which they were submitted to the constructor. The “index” for each member Series is the same, starting at 0.0 then at every “quarterLength” after, until either the last observation in the piece, or the nearest multiple before. |
---|---|
Return type: | pandas.DataFrame |
Indexers that consider repetition in any way.
Bases: vis.analyzers.indexer.Indexer
If the same event occurs many times in a row, remove all occurrences but the one with the lowest offset value (i.e., the “first” event).
Parameters: |
|
---|---|
Raises: | RuntimeError if score is the wrong type. |
Raises: | RuntimeError if score is not a list of the same types. |
The FilterByRepeatIndexer requires pandas.Series as input.
alias of Series
Make a new index of the piece, removing any event that is identical to the preceding.
Returns: | A list of the new indices. The index of each Series corresponds to the index of the Part used to generate it, in the order specified to the constructor. Each element in the Series is a basestring. |
---|---|
Return type: | list of pandas.Series |
Template for writing a new indexer. Use this class to help write a new :class`Indexer` subclass. The TemplateIndexer does nothing, and should only be used by programmers.
Bases: vis.analyzers.indexer.Indexer
Template for an Indexer subclass.
Parameters: |
|
---|
Raises: | RuntimeError if score is the wrong type. |
---|---|
Raises: | RuntimeError if score is not a list of the same types. |
Raises: | RuntimeError if required settings are not present in settings. |
The default values for settings named in possible_settings. If a setting doesn’t have a value in this constant, then it must be specified to the constructor at runtime, or the constructor should raise a RuntimeException.
This is a list of basestrings that are the names of the settings used in this indexer. Specify the types and reasons for each setting as though it were an argument list, like this:
Parameters: | u’fake_setting’ (boolean) – This is a fake setting. |
---|
Depending on how this Indexer works, you’ll either need to provie music21.stream.Part or pandas.Series.
alias of Part
Make a new index of the piece.
Returns: | A list of the new indices. The index of each Series corresponds to the index of the Part used to generate it, in the order specified to the constructor. Each element in the Series is a basestring. |
---|---|
Return type: | list of pandas.Series |
The function that indexes.
Parameters: | obj (list of the types stored in self._types) – The simultaneous event(s) to use when creating this index. |
---|
Parameters: | obj (pandas.Series of unicode) – The simultaneous event(s) to use when creating this index. |
---|
Returns: | The value to store for this index at this offset. |
---|---|
Return type: | unicode |