Table Of Contents

Previous topic

experimenters Package

Next topic

models Package

This Page

indexers Package

indexers Package

interval Module

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.

class vis.analyzers.indexers.interval.HorizontalIntervalIndexer(score, settings=None)[source]

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.

run()[source]

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
class vis.analyzers.indexers.interval.IntervalIndexer(score, settings=None)[source]

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.

default_settings = {u'simple or compound': u'compound', u'quality': False}

A dict of default settings for the IntervalIndexer.

possible_settings = [u'simple or compound', u'quality']

A list of possible settings for the IntervalIndexer.

Parameters:
  • u’simple or compound’ (unicode) – Whether intervals should be represented in their single-octave form (either u'simple' or u'compound').
  • u’quality’ (boolean) – Whether to display an interval’s quality.
required_score_type

The IntervalIndexer requires a list of Series as input. These should be the result of NoteRestIndexer.

alias of Series

run()[source]

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
vis.analyzers.indexers.interval.indexer_nq_comp(ecks)[source]

Used internally by the IntervalIndexer and HorizontalIntervalIndexer.

Call real_indexer() with settings to print compound intervals without quality.

vis.analyzers.indexers.interval.indexer_nq_simple(ecks)[source]

Used internally by the IntervalIndexer and HorizontalIntervalIndexer.

Call real_indexer() with settings to print simple intervals without quality.

vis.analyzers.indexers.interval.indexer_qual_comp(ecks)[source]

Used internally by the IntervalIndexer and HorizontalIntervalIndexer.

Call real_indexer() with settings to print compound intervals with quality.

vis.analyzers.indexers.interval.indexer_qual_simple(ecks)[source]

Used internally by the IntervalIndexer and HorizontalIntervalIndexer.

Call real_indexer() with settings to print simple intervals with quality.

vis.analyzers.indexers.interval.key_to_tuple(key)[source]

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)
vis.analyzers.indexers.interval.real_indexer(simultaneity, simple, quality)[source]

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 'Rest' strings, you can compare the duration of the piece in which the two parts do or do not have notes sounding together.

Parameters:
  • simultaneity (list of basestring) – A two-item iterable with the note names (or u'Rest') for the top then lower voice.
  • simple (boolean) – Whether intervals should be reduced to their single-octave version.
  • quality (boolean) – Whether the interval’s quality should be prepended.
Returns:

u'Rest' if one or more of the parts is u'Rest'; otherwise, the interval between parts.

Return type:

unicode string

ngram Module

Indexer to find k-part any-object n-grams.

class vis.analyzers.indexers.ngram.NGramIndexer(score, settings=None)[source]

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. Note that the default WorkflowManager is set to override this setting by dynamically adjusting to whether interval quality is set to True or False or if the user chooses to pass a custom string for this setting.

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.

default_settings = {u'horizontal': [], u'continuer': u'_', u'mark_singles': True, u'terminator': []}

A dict of default settings for the NGramIndexer.

possible_settings = [u'horizontal', u'vertical', u'n', u'mark_singles', u'terminator', u'continuer']

A list of possible settings for the NGramIndexer.

Parameters:
  • u’horizontal’ (list of int) – The parts to consider as “horizontal.”
  • u’vertical’ (list of int) – The parts to consider as “vertical.”
  • u’n’ (int) – The number of “vertical” events per n-gram.
  • u’mark_singles’ (bool) – Whether to use delimiters around a direction’s events when there is only one event in that direction (e.g., the “horizontal” maps only the activity of a single voice). (You may also use u'mark singles').
  • u’terminator’ (list of basestring) – Do not find an n-gram with a vertical item that contains any of these values.
  • u’continuer’ (basestring) – When there is no “horizontal” event that corresponds to a vertical event, this is printed instead, to show that the previous “horizontal” event continues.
required_score_type

The NGramIndexer requires pandas.Series as input.

alias of Series

run()[source]

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

noterest Module

Index note and rest objects.

class vis.analyzers.indexers.noterest.NoteRestIndexer(score, settings=None)[source]

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.

required_score_type

The NoteRestIndexer uses Part objects directly.

alias of Part

run()[source]

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
vis.analyzers.indexers.noterest.indexer_func(obj)[source]

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

offset Module

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.

class vis.analyzers.indexers.offset.FilterByOffsetIndexer(score, settings=None)[source]

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:

  • events that do not begin at an observed offset will only be included in the output if no other event occurs before the next observed offset
  • events that last for many observed offsets will be repeated for those offsets

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 5
in-T 4 ———– 3
in-B 5 1
out-S 2 1 1
out-A 7 5 5
out-T 4 4 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!

default_settings = {'method': 'ffill'}
possible_settings = ['quarterLength', 'method']

A list of possible settings for the FilterByOffsetIndexer.

Parameters:
  • ‘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).
  • ‘method’ (str or None) – The value passed as the method kwarg to reindex(). The default is 'ffill', which fills in missing indices with the previous value. This is useful for vertical intervals, but not for horizontal, where you should use None instead.
required_score_type

The FilterByOffsetIndexer uses pandas.Series objects.

alias of Series

run()[source]

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

repeat Module

Indexers that consider repetition in any way.

class vis.analyzers.indexers.repeat.FilterByRepeatIndexer(score, settings=None)[source]

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).

required_score_type

The FilterByRepeatIndexer requires pandas.Series as input.

alias of Series

run()[source]

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 Module

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.

class vis.analyzers.indexers.template.TemplateIndexer(score, settings=None)[source]

Bases: vis.analyzers.indexer.Indexer

Template for an Indexer subclass.

default_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.

possible_settings = [u'fake_setting']

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.
required_score_type

Depending on how this Indexer works, you’ll either need to provide music21.stream.Part, music21.stream.Score, or pandas.Series.

alias of Part

run()[source]

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
vis.analyzers.indexers.template.indexer_func(obj)[source]

The function that indexes.

Parameters for Indexers Using a Score :param obj: The simultaneous event(s) to use when creating this index. :type obj: list of the types stored in self._types

Parameters for Indexers Using a Series :param obj: The simultaneous event(s) to use when creating this index. :type obj: pandas.Series of unicode

Returns:The value to store for this index at this offset.
Return type:unicode