示例#1
0
 def test_book_example(self):
     location = ChromaticScale.parse_notation("4:9")
     print(location)
     index = ChromaticScale.location_to_index(location)
     print(index)
     loc = ChromaticScale.index_to_location(index)
     print(loc)
示例#2
0
 def is_location_inbounds(self, location):
     """
     Determines if given chromatic location is in bounds of range.
     
     Args:
       location: chromatic location
     Returns:
       boolean indicating if in bounds.
     """
     return self.is_inbounds(ChromaticScale.location_to_index(location))
示例#3
0
 def find_lowest_placement_in_range(self, placement):
     """
     For a given chromatic placement (0, ..., 11) find the lowest chromatic index 
     in the range for it.
     """
     if placement < 0 or placement >= 12:
         raise Exception(
             'Illegal placement value {0} must be between 0 and 11'.format(
                 placement))
     start_partition = ChromaticScale.index_to_location(self.start_index)[0]
     end_partition = ChromaticScale.index_to_location(self.end_index)[0]
     lowest_index = -1
     for partition in range(start_partition, end_partition + 1):
         if self.is_location_inbounds((partition, placement)):
             lowest_index = ChromaticScale.location_to_index(
                 (partition, placement))
             break
     return lowest_index
示例#4
0
    def test_scale(self):
        scale = ChromaticScale.get_chromatic_scale(
            ChromaticScale.parse_notation("0:9"),
            ChromaticScale.parse_notation("8:0"))
        start = ChromaticScale.location_to_index((0, 9))
        end = ChromaticScale.location_to_index((8, 0)) + 1

        for i in range(start, end):
            logging.info('{0}{1}   {1}'.format(
                i, ChromaticScale.index_to_location(i), scale[i - start]))

        assert is_close(scale[ChromaticScale.location_to_index((4, 9)) - start], 440.0), \
            "Error A:4 = {0} should be 440.0".format(scale[ChromaticScale.location_to_index((4, 9)) - start])
        assert is_close(scale[ChromaticScale.location_to_index((4, 0)) - start], 261.625565301), \
            "Error C:4 = {0} should be 261.625565301".format(scale[ChromaticScale.location_to_index((4, 0)) - start])
示例#5
0
 def test_location_to_index(self):
     for i in range(1, 4):
         for j in range(0, 12):
             index = ChromaticScale.location_to_index((i, j))
             assert index == 12 * i + j