Skip to main content

Module search

Module search 

Source
Expand description

Finding music in streams: lyrics as text. Finding music in streams: music21’s search package. A StreamSearcher and the searches beside it find runs of notes by name, rhythm or anything else; the translations turn notes into text, which the approximate searches compare as Python’s difflib does; and a LyricSearcher finds text in a stream’s lyrics, and the notes it is sung to. index_score_parts cuts each part of a score into overlapping stretches of that text, and score_similarity compares every stretch of some scores with every other. A SegmentMatcher finds rows and sets of pitch classes in the notes of a stream, and labels them there.

Structs§

ContiguousSegment
A run of notes and chords of one part: music21’s ContiguousSegmentOfNotes.
ContiguousSegmentSearcher
Finds every run of a stream’s notes and chords that is a segment of a given length, part by part: music21’s ContiguousSegmentSearcher.
IndexedLyric
One lyric of a stream and where its text sits in the text searched: music21’s IndexedLyric. Positions count characters, as Python’s do.
LyricMatch
A stretch of lyrics a search found: music21’s search.lyrics SearchMatch.
LyricSearcher
Finds text in a stream’s lyrics: music21’s LyricSearcher. Each verse’s lyrics are read as one text, syllables of a word run together and words apart, and the verses one after another with LINE_BREAK between them; a search finds each place the text comes and the lyrics and notes there.
MeasureRhythm
A rhythm the measures of a stream share, and which measures share it.
SearchMatch
A run of elements a search found: music21’s search.base SearchMatch.
Searched
One element of a stream as a search meets it, with where it is: what music21’s stream iterators hand a search.
SegmentAt
Where a segment comes from in an index of scores.
SegmentMatcher
Finds the runs of a stream’s notes and chords that are segments or sets of pitch classes searched for: music21’s SegmentMatcher and the matchers built on it, chosen by Matching.
SegmentNote
One note or chord of a ContiguousSegment, and where it stands.
SegmentSimilarity
How alike two segments are: one row of music21’s scoreSimilarity.
Segments
A part cut into stretches of its translated notes, and the measures each stretch runs from and to: one entry of music21’s score index.
StreamSearcher
Searches a stream for runs of elements matching a list of terms, the terms compared by a list of algorithms: music21’s StreamSearcher. A run matches unless an algorithm says one of its elements does not; with only the wildcard algorithm, as it starts, every run matches.
Translation
Notes and rests as text to search, and the measure each piece of it comes from.

Enums§

Algorithm
How a StreamSearcher compares an element of the stream with the search term it is lined up with: each answers that they match, that they do not, or nothing, leaving it to the next.
Filter
Which elements of the stream a StreamSearcher looks at.
LyricIdentifier
Which verse a lyric belongs to: the name a score gave it or, failing one, its number, which music21 keeps apart even where the name is a number written out.
Matching
How a SegmentMatcher tells a run of pitch classes the same as one searched for.
Repetitions
How a ContiguousSegmentSearcher reads notes that repeat a pitch class: music21’s reps.
SearchTerm
One place in what is searched for: music21’s search list entry.

Constants§

LINE_BREAK
What music21 writes between the lyrics of one verse and the next in the text it searches: LINEBREAK_TOKEN.

Functions§

approximate_note_search
How alike each other stream is to this one, as the text of their notes and rests – pitch, length and tie – best first: music21’s approximateNoteSearch. Each is the other stream’s index and its likeness, music21’s matchProbability.
approximate_note_search_no_rhythm
The same, by pitch alone: music21’s approximateNoteSearchNoRhythm.
approximate_note_search_only_rhythm
The same, by length alone: music21’s approximateNoteSearchOnlyRhythm.
approximate_note_search_weighted
The same, three parts by pitch to one by length: music21’s approximateNoteSearchWeighted.
index_score_parts
Each part of a score cut into segments, by music21’s defaults – thirty characters a segment, twelve overlapping, pitches alone: music21’s indexScoreParts.
index_score_parts_with
The same, cut as asked.
iterated
The elements of a stream itself, not of the streams it holds: music21’s iter().
most_common_measure_rhythms
The rhythms of a stream’s measures, nested ones included, most common first, those as common in the order first met: music21’s mostCommonMeasureRhythms, without the copy of each first measure transposed to start on C5 that music21 keeps beside it.
note_name_rhythmic_search
Where each run of elements starts whose names and lengths are those searched for: music21’s noteNameRhythmicSearch.
note_name_search
Where each run of elements starts whose names – a note’s pitch name, rest – are those searched for, a wildcard matching any: music21’s noteNameSearch.
notes_and_rests
The notes, chords and rests of recursed: music21’s recurse().notesAndRests.
recursed
Every element of a stream, nested ones included, each before what it holds: music21’s recurse().
rhythmic_search
Where each run of elements starts whose lengths are those searched for, a wildcard or a term of any length matching any: music21’s rhythmicSearch.
score_similarity
Every segment of an index of named scores at least minimum_length characters long, compared with every such segment of each score after its own: music21’s scoreSimilarity, by difflib. A score’s segments are not compared with each other, as music21 compares none. With include_reverse, each comparison comes again with its two segments the other way round.
similarity
How alike two stretches of text are, as music21’s approximate searches measure it: Python’s difflib.SequenceMatcher(None, a, b).ratio().
translate_diatonic_stream_to_string
Notes and rests as text of their steps, a letter for each note – A to G where it is as long as the note before, seven letters on where it is longer, fourteen where it is shorter – and Z for a run of rests: music21’s translateDiatonicStreamToString. A note tied on from the one before is left out.
translate_duration_to_bytes
An element’s length as one character, ten times the base-two logarithm of 256 times its quarter length, kept within one to 127: music21’s translateDurationToBytes.
translate_intervals_and_speed
Notes and rests as text of the intervals between them, up to thirteen semitones either way, and whether each is as long as, shorter or longer than the one before, a space for a run of rests: music21’s translateIntervalsAndSpeed. The first note’s interval is from the first note.
translate_monophonic_part_to_segments
A part’s notes, written by translate, cut into stretches segment_length characters long, each starting segment_length - overlap after the one before, the last as long as what is left: music21’s translateMonophonicPartToSegments. Each stretch’s measures are read off the translation’s measures at its first and last character, as music21 reads them, which is a note’s measure only where the translation writes one character a note, as translate_stream_to_string_no_rhythm, music21’s default, does.
translate_note_tie_to_byte
An element’s tie as text: s for one starting, c for one going on, e for one ending, and nothing otherwise: music21’s translateNoteTieToByte.
translate_note_to_byte
An element as one character: a note’s MIDI number, a chord’s first pitch’s, and 127 for anything else – a rest, an unpitched stroke, a chord of nothing: music21’s translateNoteToByte.
translate_note_with_duration_to_bytes
An element as its pitch, length and, if asked, tie characters: music21’s translateNoteWithDurationToBytes.
translate_stream_to_string
Notes and rests as text, each its pitch, length and tie characters: music21’s translateStreamToString.
translate_stream_to_string_no_rhythm
Notes and rests as text of their pitches alone: music21’s translateStreamToStringNoRhythm.
translate_stream_to_string_only_rhythm
Notes and rests as text of their lengths alone: music21’s translateStreamToStringOnlyRhythm.