def test_EfficientVoiceLeading(): """Test EfficientVoiceLeading module class.""" D_minor_scale = MinorScale('D') D_minor_scale = Chord(D_minor_scale.getPitches('D4', 'C5')) E_major_scale = MajorScale('E') E_major_scale = Chord(E_major_scale.getPitches('E4', 'D#5')) scale = ChromaticScale('C') voice_leading = EfficientVoiceLeading( scale=ChromaticScale('C'), metric=lambda delta: la.norm(delta, inf)) vl, dist = voice_leading( D_minor_scale, E_major_scale, ) assert vl == [1, 1, 0, 1, 1, 0, 1] assert dist == 1.0
def test_scalePoint(): """Test scalePoint module method.""" scale = ChromaticScale('C') scalar_point = scalePoint(chord, scale) assert scalar_point == [0, 4, 7] scale = MajorScale('C') scalar_point = scalePoint(chord, scale) assert scalar_point == [0, 2, 4]
def test_standardSimplex(): """Test standardSimplex module method.""" scale = ChromaticScale('C') standard_simplex = standardSimplex(chord, scale) assert standard_simplex == [11 / 12, 4 / 12, 3 / 12] standard_simplex = standardSimplex(chord, scale, False) assert standard_simplex == [11, 4, 3] scale = MajorScale('C') standard_simplex = standardSimplex(chord, scale) assert standard_simplex == [6 / 7, 2 / 7, 2 / 7] standard_simplex = standardSimplex(chord, scale, False) assert standard_simplex == [6, 2, 2]
""" 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.symbol import chordSymbolFigure from music21.scale import ChromaticScale from orbichord.identify import chordSymbolIndex scale = ChromaticScale('C') chord_generator = Generator(dimension=4, pitches=scale.getPitches('C', 'B')) for chord in chord_generator.run(): print('{} {} - {}'.format(chord, chord.orderedPitchClassesString, chordSymbolFigure(chord, inversion=0)))
chordA = Chord('C E G') chordB = Chord('A E C') # Interscalar assuming any permutation matrix = interscalarMatrix(chordA, chordB, scale) print(matrix) # Interscalar assuming cyclic permutation matrix = interscalarMatrix(chordA, chordB, scale, permutation=Permutation.CYCLIC) print(matrix) # Interscalar assuming no permutation matrix = interscalarMatrix(chordA, chordB, scale, permutation=Permutation.NONE) print(matrix) # Chords with duplicated pitches scale = ChromaticScale('C') chordA = Chord('E- A- C C') chordB = Chord('E E A- B') # Interscalar assuming any permutation matrix = interscalarMatrix(chordA, chordB, scale) print(matrix) # Interscalar without cardinality invariance matrix = interscalarMatrix(chordA, chordB, scale, cardinality=False) print(matrix)
""" 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.symbol import chordSymbolFigure from music21.scale import ChromaticScale def combinator(iterable, dimension): return itertools.product(iterable, repeat = dimension) scale = ChromaticScale('C') chord_generator = Generator( combinator = combinator, pitches = scale.getPitches('C','B') ) for chord in chord_generator.run(): print('{} {} - {}'.format( chord, chord.orderedPitchClassesString, chordSymbolFigure(chord, inversion=0) ))
"""Create maps used by orbichord.identify module.""" from collections import OrderedDict import music21.chord from music21.scale import ChromaticScale import music21.harmony as harmony from orbichord.identify import chordSymbolIndex from pprint import pprint chords = OrderedDict() # Get chromatic scale pitches = ChromaticScale().getPitches('C', 'B') # Loop over all possible roots for add1 in range(13): for kind in harmony.CHORD_TYPES.keys(): for root in pitches: ref = harmony.ChordSymbol(root=root, kind=kind) basses = [None] + list(ref.pitches)[1:] inversions = [] for bass in basses: bass = bass.name if bass else None chord = harmony.ChordSymbol(root=root, kind=kind, bass=bass) if add1 > 0: chord.add(add1 - 1) key = chordSymbolIndex(chord) try: name = harmony.chordSymbolFigureFromChord(chord) except: continue