orbichord package

orbichord.chord module

Implement identified chords.

class orbichord.chord.IdentifiedChord(identify: Callable[[music21.chord.Chord], str] = <function IdentifiedChord.<lambda>>, notes=None, **keywords)[source]

Bases: music21.chord.Chord

Extend Chord to be a hashable object.

The hash is contructed from a identity function that map a chord in to a string.

Parameters
  • identify (Callable[[Chord], str], optional) – Funtion to indentify chords.

  • notes – Argument pass to chord constructor.

  • keywords – Argument pass to chord constructor.

Examples

>>> from orbichord.chord import IdentifiedChord
>>> C = IdentifiedChord(notes = 'C4 E4 G4')
>>> print(C.orderedPitchClassesString)
<047>
>>> print(C.identity)
<047>
>>> print(C.identify(C))
<047>
>>> print(hash(C))
5261361699489349224
__eq__(other)[source]

Overload comparison based hashable implementation.

__hash__()[source]

Return a has of the string.

property identify

Return identify function.

property identity

Return identity string.

orbichord.chordinate module

Implement tools to compute chordinates and distances in a given scale.

class orbichord.chordinate.EfficientVoiceLeading(scale: music21.scale.ConcreteScale, metric: Callable[[list], float], permutation: orbichord.chordinate.Permutation = <Permutation.ANY: 3>)[source]

Bases: object

Compute efficient voice leading between two chords.

Parameters
  • scale (ConcreteScale) – Scale use to define voice leading steps

  • metric (Callable[[list], float]) – Metric function

  • permutation (Permutation, optional) – Permutation invariance in the voice leading.

Examples

>>> from music21.chord import Chord
>>> from music21.scale import MajorScale
>>> from numpy import inf
>>> from numpy import linalg as la
>>> from orbichord.chordinate import EfficientVoiceLeading
>>> scale = MajorScale('C')
>>> C = Chord('C E G')
>>> G = Chord('G B D')
>>> voice_leading = EfficientVoiceLeading(
...     scale = scale,
...     metric = lambda delta: la.norm(delta, inf)
>>> )
>>> vl, dist = voice_leading(C, G)
>>> print(vl, dist)
[-1, -1, 0] 1.0
__call__(chordA: music21.chord.Chord, chordB: music21.chord.Chord) → tuple[source]

Return the efficient voice leading and its distance

Parameters
  • chrodA (Chrod) – Voice leading start chord

  • chrodA – Voice leading end chord

Returns

Efficient voice leading scalar steps and its distance

Return type

tuple

property metric

Returns voice leaging metric.

property permutation

Returns voice leaging metric.

property scale

Returns voice leaging scale.

class orbichord.chordinate.Permutation[source]

Bases: enum.Enum

Define type permutation used interscalar matrix.

ANY = 3
CYCLIC = 2
NONE = 1
orbichord.chordinate.interscalarMatrix(chordA: music21.chord.Chord, chordB: music21.chord.Chord, scale: music21.scale.ConcreteScale, cardinality: bool = True, permutation: orbichord.chordinate.Permutation = <Permutation.ANY: 3>) → list[source]

Compute the interscalar matrix between two chords

Parameters
  • chrodA (Chrod) – Voice leading start chord.

  • chrodA – Voice leading end chord

  • scale (ConcreteScale) – Scale use a metric.

  • cardinality (bool, optional) – If true chord cardinality is invariant.

  • permutation (Permutation, optional) – Permutation invariance in the interscalar matrix.

Returns

List of voice leading scalar steps

Return type

list

Examples

>>> from music21.chord import Chord
>>> from music21.scale import MajorScale
>>> from orbichord.chordinate import interscalarMatrix, Permutation
>>> scale = MajorScale('C')
>>> chordA = Chord('C E G')
>>> chordB = Chord('A C E')
>>> matrix = interscalarMatrix(
...     chordA, chordB, scale
>>> )
>>> print(matrix)
[[0, 0, 1], [2, 3, 3], [-2, -2, -2]]
orbichord.chordinate.mod(x, y, d)[source]

Implement a modify module to provide shortest possible voice leading.

orbichord.chordinate.scalePoint(chord: music21.chord.Chord, scale: music21.scale.ConcreteScale) → list[source]

Compute chord coordinates using the degree for a given scale

Parameters
  • chrod (Chrod) – Chord to estimate normal order

  • scale (ConcreteScale) – Scale use as metric step

Returns

List with scalar normal order

Return type

list

Examples

>>> from music21.chord import Chord
>>> from music21.scale import MajorScale
>>> from orbichord.chordinate import scalePoint
>>> scale = MajorScale('C')
>>> chord = Chord('C E G')
>>> scalePoint(chord, scale)
[0, 2, 4]
orbichord.chordinate.standardSimplex(chord: music21.chord.Chord, scale: music21.scale.ConcreteScale, normalize: bool = True) → list[source]

Compute chord scale point in the standard simplex

Parameters
  • chrod (Chrod) – Chord to estimate normal order

  • scale (ConcreteScale) – Scale use as metric step

  • normalize (int, optional) – Normalize coordinates by the number of scale degrees

Returns

List with scalar point within standard simplex

Return type

list

Examples

>>> from music21.chord import Chord
>>> from music21.scale import ChromaticScale
>>> from orbichord.chordinate import standardSimplex
>>> scale = ChromaticScale('C')
>>> chord = Chord('C E G')
>>> standardSimplex(chord, scale)
[0.9166666666666666, 0.3333333333333333, 0.25]
>>> standardSimplex(chord, scale, normalize=False)
[11, 4, 3]

orbichord.generator module

Generate quotient space of n-pich classes.

class orbichord.generator.Generator(pitches: list, dimension: int = 3, combinator: Callable[[Iterable, int], Iterator] = <class 'itertools.combinations_with_replacement'>, identify: Callable[[music21.chord.Chord], str] = <function Generator.<lambda>>, select: Callable[[music21.chord.Chord], bool] = <function hasChordSymbolFigure>)[source]

Bases: object

Generate the space of n-pitches chords.

Generate the space of n-pitches chords. The list of pitches to be used in the generation needs to be provided when instantiating the generator.

It is assumed that chords are musical objects which are at least invariant under scale pitch shifts (O). Any other invariance depends on how chord pitches are combined and how chords are identified.

You can further restrict the generation of chords by passing a select function that restricts the type of chords yielded by the generator.

By default, the generator will produce 3-pitched chords with the same invariances as a pitch-class ser:

  • scale pitch shifts (O),

  • pitch class permutation (P),

  • pitch class cardinality (C)

Moreover, by default only chords with know symbols are selected to be generated.

Parameters
  • pitches (list) – List of music21.pitch.Pitch.

  • dimension (int, optional) – Dimension of the space.

  • combinator (Callable[[Iterable, int], Iterator], optional) – Iterator function to generate all chord combinations.

  • identify (Callable[Chord, str], optional) – Funtion to indentify chords.

  • select (Callable[Chord, str], optional) – Function to select chords.

Raises

ValueError – if the dimension is negative.

References

  • Tymoczko, Dmitri. “The geometry of musical chords.” Science 313.5783 (2006): 72-74.

  • Callender, Clifton, Ian Quinn, and Dmitri Tymoczko. “Generalized voice-leading spaces.” Science 320.5874 (2008): 346-348.

  • Dmitri Tymoczko, A Geometry of Music: Harmony and Counterpoint in the Extended Common Practice, Oxford University Press, 2011.

Examples

>>> from orbichord.generator import Generator
>>> from orbichord.symbol import chordSymbolFigure
>>> from music21.scale import MajorScale
>>> scale = MajorScale('C')
>>> chord_generator = Generator(
...     pitches = scale.getPitches('C','B'),
...     select = lambda chord: chord.isTriad()
>>> )
>>> for chord in chord_generator.run():
...     print('{} {} - {}'.format(
...     chord,
...     chord.orderedPitchClassesString,
...     chordSymbolFigure(chord, inversion=0)
... ))
<music21.chord.Chord C0 E0 G0> <047> - C
<music21.chord.Chord C0 E0 A0> <049> - Am
<music21.chord.Chord C0 F0 A0> <059> - F
<music21.chord.Chord D0 F0 A0> <259> - Dm
<music21.chord.Chord D0 F0 B0> <25B> - Bdim
<music21.chord.Chord D0 G0 B0> <27B> - G
<music21.chord.Chord E0 G0 B0> <47B> - Em
property combinator

Return the generator combinator.

property dimension

Return the generator dimension.

property identify

Return the function use to identify chords.

property pitches

Return the generator pitches.

run() → Iterator[music21.chord.Chord][source]

Generate a sequence of chords.

Yields

Iterator[Chord] – An iterator to the chords in the space.

property select

Return function to select chords.

orbichord.graph module

Create a graph with chords as nodes.

orbichord.graph.convertGraphToData(graph: networkx.classes.graph.Graph)[source]

Convert a chord graph to columnal dataset.

Parameters

graph (Graph) – A graph of chords.

Returns

  • edges (list) – List of graph edges.

  • vertices (list) – List of vertices

orbichord.graph.createGraph(generator: orbichord.generator.Generator, voice_leading: orbichord.chordinate.EfficientVoiceLeading, tolerance: Callable[[float], bool], label: Callable[[music21.chord.Chord], str] = <function <lambda>>) → networkx.classes.graph.Graph[source]

Create a graph as adjacency list of chords.

Parameters
  • generator (Generator) – An orbichord generator.

  • voice_leading (EfficientVoiceLeading) – A voice leading object.

  • tolerance (Callable[[float], bool]) – Tolerance function.

  • labed

Returns

graph – Networkx Graph object.

Return type

Graph

orbichord.identify module

Define a set of common chord identyfier.

orbichord.identify.base10toN(num: int, base: int = 12)[source]

Change to given base upto base 36 is supported.

Parameters
  • num (int) – Integer to be transform to new base.

  • base (int) – Based to use write the integer.

Returns

String with number digits in new base.

Return type

str

References

orbichord.identify.chordPitchClasses(chord: music21.chord.Chord) → str[source]

Identify chords based on its pitch classes.

Parameters

chord (Chord) – Chord to be identified.

Returns

A string with the pitch classes.

Return type

str

orbichord.identify.chordPitchNames(chord: music21.chord.Chord) → str[source]

Identify chords based on its pitch names.

Parameters

chord (Chord) – Chord to be identified.

Returns

A string with the pitch names.

Return type

str

orbichord.identify.chordSymbolIndex(chord: music21.chord.Chord) → str[source]

Identify chords based on its chord symbol index.

The chord symbol index is an index that is unique to each named chord.

Parameters

chord (Chord) – Chord to be identified.

Returns

A string with the pitch names.

Return type

str

orbichord.maps module

orbichord.symbol module

Map postonal chord names to symbols commonly found on lead sheets.

orbichord.symbol.chordSymbolFigure(chord: music21.chord.Chord, inversion: int = None, enharmonic: int = 0) → str[source]

Identify chords based chord symbol figure.

This only applies to chords commonly found on lead sheets.

Parameters
  • chord (Chord) – Chord to be identified.

  • inversion (int, optional) – Inversion index.

  • enharmonic (int, optional) – Enharmonic index

Returns

A string with with the chord symbol figure.

Return type

str

orbichord.symbol.hasChordSymbolFigure(chord: music21.chord.Chord) → bool[source]

Return true if the chord has figure.

This only applies to chords commonly found on lead sheets.

Parameters

chord (Chord) – Chord to be identified.

Returns

Return if symbol figure exist (named chord).

Return type

bool

orbichord.utils module

orbichord.utils.playAudio(stream)[source]

Generate audio play from stream.

orbichord.utils.renderWithJS(stream)[source]

Show a using javascript.

References

https://notebooks.azure.com/OUsefulInfo/projects/gettingstarted/html/4.1.0%20Music%20Notation.ipynb

orbichord.utils.renderWithLily(stream)[source]

Render LilyPond in Jupyter notebook.

orbichord.utils.showMusicXML(xml)[source]

Show music xml using javascript.

References

https://notebooks.azure.com/OUsefulInfo/projects/gettingstarted/html/4.1.0%20Music%20Notation.ipynb

Module contents