def test_createGraph(): """Test createGraph module member.""" scale = MajorScale('C') chord_generator = Generator( pitches = scale.getPitches('C','B'), select = lambda chord: chord.isTriad() ) max_norm_vl = EfficientVoiceLeading( scale = scale, metric = lambda delta: la.norm(delta, inf) ) graph, _ = createGraph( generator = chord_generator, voice_leading = max_norm_vl, tolerance = lambda x: x == 1.0, label = lambda chord: chordSymbolFigure(chord, inversion=0) ) string = '' for node, neighbors in graph.adjacency(): line = node + ': ' for neighbor, edge in neighbors.items(): line += ' {} ({}),'.format( neighbor, edge['distance'] ) string += line[:-1] + '\n' assert string[:-1] == graph_string
""" Example of generator primitives. This example generates the space of C chords identify by their ordered pitch class string that are also triads. """ 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)))
scale = MajorScale('C') chord_generator = Generator(pitches=scale.getPitches('C', 'B'), combinator=combinator, identify=chordPitchNames, select=lambda chord: chord.isTriad()) max_norm_vl = EfficientVoiceLeading(scale=scale, metric=lambda delta: la.norm(delta, inf), permutation=Permutation.NONE) graph, _ = createGraph( generator = chord_generator, voice_leading = max_norm_vl, tolerance = lambda x: x == 1.0, label = lambda chord: chordSymbolFigure(chord) +\ ' (' + chordPitchNames(chord) + ')' ) for node, neighbors in graph.adjacency(): string = node + ': ' for neighbor, edge in neighbors.items(): string = string + ' {} ({}),'.format(neighbor, edge['distance']) print(string[:-1]) good_twin, evil_twin = (graph.subgraph(c) for c in connected_components(graph)) print() print('Evil twin graph component') for node, neighbors in evil_twin.adjacency():
""" Example of generator primitives. This example generates the space of C chords identify by their ordered pitch class string that are also triads. """ import itertools from orbichord.generator import Generator from orbichord.identify import chordPitchNames from orbichord.symbol import chordSymbolFigure from music21.scale import MajorScale def combinator(iterable, dimension): return itertools.product(iterable, repeat=dimension) scale = MajorScale('C') chord_generator = Generator(pitches=scale.getPitches('C', 'B'), combinator=combinator, identify=chordPitchNames, select=lambda chord: chord.isTriad()) for chord in chord_generator.run(): print('{} {} - {}'.format(chord, chord.orderedPitchClassesString, chordSymbolFigure(chord)))
"""Example of chord graph creation.""" from music21.scale import MajorScale from numpy import inf from numpy import linalg as la from orbichord.chordinate import EfficientVoiceLeading from orbichord.graph import createGraph, convertGraphToData from orbichord.generator import Generator from orbichord.symbol import chordSymbolFigure scale = MajorScale('C') chord_generator = Generator(pitches=scale.getPitches('C', 'B'), select=lambda chord: chord.isTriad()) max_norm_vl = EfficientVoiceLeading(scale=scale, metric=lambda delta: la.norm(delta, inf)) graph, _ = createGraph( generator=chord_generator, voice_leading=max_norm_vl, tolerance=lambda x: x == 1.0, label=lambda chord: chordSymbolFigure(chord, inversion=0)) for node, neighbors in graph.adjacency(): string = node + ': ' for neighbor, edge in neighbors.items(): string = string + ' {} ({}),'.format(neighbor, edge['distance']) print(string[:-1])