コード例 #1
0
 def add_voice(self, voice: list, offset: int = 0):
     try:
         assert len(voice) + offset <= self.size
     except AssertionError:
         raise ValueError(
             "Voice doesn't fit in PitchMap. PitchMap is too short!")
     voice = [PitchMapTone(mel.EmptyPitch(), 0)
              for i in range(offset)] + list(voice)
     while len(voice) < self.size:
         voice.append(PitchMapTone(mel.EmptyPitch(), 0))
     self.__voices.add(tuple(voice))
コード例 #2
0
 def _data(self):
     data = [set([]) for i in range(self.size)]
     for v in self.voices:
         for i, sub in enumerate(v):
             if sub.pitch != mel.EmptyPitch():
                 data[i].add(sub)
     return data
コード例 #3
0
 def add_voice(self, voice: list, offset: int = 0):
     try:
         assert len(voice) + offset <= len(self)
     except AssertionError:
         raise ValueError(
             "Voice doesn't fit in PitchMap. PitchMap is too short!")
     for i, tone in enumerate(voice):
         if tone.pitch != mel.EmptyPitch() and tone.weight > 0:
             self.add_tone(i + offset, tone)
コード例 #4
0
 def sub(melody):
     new = []
     for i, it0 in enumerate(melody):
         try:
             it1 = melody[i + 1]
         except IndexError:
             new.append(it0)
             break
         pitch_test = (
             all(p == mel.EmptyPitch() for p in it0.pitch),
             all(p == mel.EmptyPitch() for p in it1.pitch),
         )
         if all(pitch_test):
             t_new = type(it0)(
                 it0.pitch, it0.duration + it1.delay, it0.duration + it1.duration
             )
             return new + sub([t_new] + melody[i + 2 :])
         else:
             new.append(it0)
     return new
コード例 #5
0
 def match(self, idx: int, pitch: ji.JIPitch):
     data = self[idx]
     harmonicity_weight_pairs = []
     for sub in data:
         if sub.pitch != mel.EmptyPitch():
             harmonicity = self.harmonicity_function(sub.pitch, pitch)
             harmonicity_weight_pairs.append((harmonicity, sub.weight))
     full_harmonicity = sum(p[0] * p[1]
                            for p in harmonicity_weight_pairs) / sum(
                                p[1] for p in harmonicity_weight_pairs)
     return full_harmonicity
コード例 #6
0
 def calculate_harmonicity_of(self, idx: int):
     item = self[idx]
     item = filter(lambda p: p.pitch != mel.EmptyPitch(), item)
     combinations = itertools.combinations(item, 2)
     harmonicity_weight_pairs = tuple(
         (self.harmonicity_function(p0.pitch, p1.pitch),
          p0.weight + p1.weight) for p0, p1 in combinations)
     if harmonicity_weight_pairs:
         return sum(p[0] * p[1] for p in harmonicity_weight_pairs) / sum(
             p[1] for p in harmonicity_weight_pairs)
     else:
         return 0
コード例 #7
0
    def convert2abjad_pitches(self, pitches) -> list:
        res = []
        for pitch in pitches:
            chord = []
            for p in pitch:
                if p != mel.EmptyPitch():
                    res_string = None
                    for s in self.strings:
                        if p == s.pitch:
                            res_string = s.number
                            break

                    if res_string is not None:
                        pitch_number = Monochord.convert_string_number2pitch_number(
                            res_string)
                        abjad_pitch = abjad.NumberedPitch(pitch_number)
                        chord.append(abjad_pitch)
                    else:
                        raise ValueError(
                            "Pitch: {0} could not be found in Monochord-Tuning!"
                            .format(p))
            res.append(chord)
        return res