示例#1
0
def _generate_simple_format():
    unit = Fraction(1, 2)
    quarter_durations = [x * unit for x in range(1, 8)]
    intervals = list(range(1, 7))
    midis = dToX(intervals, first_element=60)
    output = SimpleFormat(quarter_durations=quarter_durations, midis=midis)
    return output
示例#2
0
    def iterator(self):

        if self._iterator is None:

            def scale(old_value, old_lower_limit, old_higher_limit,
                      new_lower_limit, new_higher_limit):
                old_range = old_higher_limit - old_lower_limit
                if old_range == 0:
                    new_value = new_lower_limit
                else:
                    new_range = (new_higher_limit - new_lower_limit)
                    new_value = (((old_value - old_lower_limit) * new_range) /
                                 old_range) + new_lower_limit
                return new_value

            if not self.directions:
                raise AttributeError('set directions')
            if not self.proportions:
                raise AttributeError('set proportions')
            if not self.midi_range:
                raise AttributeError('set midi_range')
            if not self.microtone:
                raise AttributeError('set microtone')

            intervals = [
                proportion * self.direction_iterator.__next__()
                for proportion in self.proportions
            ]
            midis = basic_functions.dToX(intervals)
            midis = [
                scale(midi, min(midis), max(midis), min(self.midi_range),
                      max(self.midi_range)) for midi in midis
            ]

            grid = 2 / self.microtone
            quantized_positions = get_quantized_positions(midis,
                                                          grid_size=grid)
            quantized_midis = [float(midi) for midi in quantized_positions]

            self._iterator = iter(quantized_midis)

        return self._iterator
示例#3
0
 def get_quarter_positions(self):
     return dToX(self.get_quarter_durations())
示例#4
0
 def inverse(self):
     intervals = xToD([midi.value for midi in self.midis])
     intervals = [-interval for interval in intervals]
     self.midis = dToX(intervals, first_element=self.midis[0].value)