Пример #1
0
 def test_interval(self):
     """
     Try getting the interval between two chords and check it comes out 
     as expected.
     
     """
     # Some randomly chosen tests
     tests = [
         (0, "C", "C", True),
         (2, "F", "G", False),
         (4, "D", "F#", False),
         (6, "B", "F", True),
         (8, "F", "Db", False),
         (10, "Ab", "F#", False),
     ]
     for interval, lower, upper, invertible in tests:
         c0 = Chord(lower)
         c1 = Chord(upper)
         self.assertEqual(interval, Chord.interval(c0, c1))
         # Try inverting the interval and check it's only the same in the
         #  cases where the interval is its own inverse
         if invertible:
             self.assertEqual(interval, Chord.interval(c1, c0))
         else:
             self.assertNotEqual(interval, Chord.interval(c1, c0))
Пример #2
0
def observation_from_chord_pair(crd1, crd2, chordmap):
    if crd2 is None:
        interval = 0
    else:
        interval = Chord.interval(Chord.from_name(str(crd1)), Chord.from_name(str(crd2)))
    if not isinstance(crd1, Chord) and not isinstance(crd1, DbChord):
        crd1 = Chord.from_name(crd1)
    return "%d-%s" % (interval, chordmap[crd1.type])
Пример #3
0
def observation_from_chord_pair(crd1, crd2):
    if crd2 is None:
        interval = 0
    else:
        interval = Chord.interval(Chord.from_name(str(crd1)), Chord.from_name(str(crd2)))
    if not isinstance(crd1, Chord):
        crd1 = Chord.from_name(str(crd1))
    return "%d-%s" % (interval, crd1.type)
Пример #4
0
 def test_interval(self):
     """
     Try getting the interval between two chords and check it comes out 
     as expected.
     
     """
     # Some randomly chosen tests
     tests = [(0, "C", "C", True), (2, "F", "G", False),
              (4, "D", "F#", False), (6, "B", "F", True),
              (8, "F", "Db", False), (10, "Ab", "F#", False)]
     for interval, lower, upper, invertible in tests:
         c0 = Chord(lower)
         c1 = Chord(upper)
         self.assertEqual(interval, Chord.interval(c0, c1))
         # Try inverting the interval and check it's only the same in the
         #  cases where the interval is its own inverse
         if invertible:
             self.assertEqual(interval, Chord.interval(c1, c0))
         else:
             self.assertNotEqual(interval, Chord.interval(c1, c0))
Пример #5
0
def interval_observation_from_chord_string_pair(chord1, chord2, type_mapping=None):
    """
    Given two strings representing chords, produces a string representing 
    a chord observation of the form x-t, where x is the interval between 
    the chords (numeric) and t is the type of the first chord.
    """
    from jazzparser.data import Chord
    chord1 = Chord.from_name(chord1)
    if chord2 is None:
        interval = ""
    else:
        chord2 = Chord.from_name(chord2)
        interval = "%d" % Chord.interval(chord1,chord2)
    # Apply a mapping to the chord type if one was given
    if type_mapping is not None:
        ctype = type_mapping[chord1.type]
    else:
        ctype = chord1.type
    return "%s-%s" % (interval, ctype)
Пример #6
0
def interval_observation_from_chord_string_pair(chord1,
                                                chord2,
                                                type_mapping=None):
    """
    Given two strings representing chords, produces a string representing 
    a chord observation of the form x-t, where x is the interval between 
    the chords (numeric) and t is the type of the first chord.
    """
    from jazzparser.data import Chord
    chord1 = Chord.from_name(chord1)
    if chord2 is None:
        interval = ""
    else:
        chord2 = Chord.from_name(chord2)
        interval = "%d" % Chord.interval(chord1, chord2)
    # Apply a mapping to the chord type if one was given
    if type_mapping is not None:
        ctype = type_mapping[chord1.type]
    else:
        ctype = chord1.type
    return "%s-%s" % (interval, ctype)
Пример #7
0
def observation_from_chord_pair(crd1, crd2):
    if crd1 is None or crd2 is None:
        return "0"
    return "%d" % Chord.interval(Chord.from_name(str(crd1)), Chord.from_name(str(crd2)))