Ejemplo n.º 1
0
 def estimate_rhythm(self, melody: old.Melody) -> tuple:
     melody.dur = rhy.Compound(melody.dur).stretch(self.stretch_factor)
     melody.delay = rhy.Compound(melody.delay).stretch(self.stretch_factor)
     melody = quantizise.quantisize_rhythm(
         melody, self.n_divisions, self.min_tone_size, self.min_rest_size
     )
     melody.dur = rhy.Compound(melody.dur).stretch(self.post_stretch_factor)
     melody.delay = rhy.Compound(melody.delay).stretch(self.post_stretch_factor)
     return melody
Ejemplo n.º 2
0
    def __init__(
        self,
        voice: old.Melody,
        new_sample_positions: tuple,
        sample_per_change: tuple,
        make_envelope: bool,
        average_volume: float,
        min_volume: float,
        max_volume: float,
        duration: float,
        tempo_factor: float,
        shadow_time: float,
        crossfade_duration: float = 0.25,
        anticipation_time: float = 0,
        overlaying_time: float = 0,
        attack_duration: infit.InfIt = infit.Value(0.5),
        release_duration: infit.InfIt = infit.Value(0.5),
        random_seed: int = 100,
    ) -> None:

        assert max_volume > min_volume
        assert min_volume > average_volume

        if not isinstance(attack_duration, infit.InfIt):
            attack_duration = infit.Value(attack_duration)

        if not isinstance(release_duration, infit.InfIt):
            release_duration = infit.Value(release_duration)

        import random as random_module

        random_module.seed(random_seed)

        self.__random_module = random_module

        voice.delay = rhy.Compound(voice.delay).stretch(tempo_factor)
        voice.dur = rhy.Compound(voice.dur).stretch(tempo_factor)

        self.__sndinfo_per_sample = {
            sample: pyo.sndinfo(sample) for sample in set(sample_per_change)
        }
        self.__n_channels_per_sample = {
            sample: self.__sndinfo_per_sample[sample][3]
            for sample in self.__sndinfo_per_sample
        }
        self.__duration_per_sample = {
            sample: self.__sndinfo_per_sample[sample][1]
            for sample in self.__sndinfo_per_sample
        }
        self.__new_sample_positions = new_sample_positions
        self.__sample_per_change = sample_per_change
        self.__duration = duration
        self.__envelope = self.mk_envelope(
            voice,
            shadow_time,
            duration,
            average_volume,
            min_volume,
            max_volume,
            make_envelope,
            anticipation_time,
            overlaying_time,
        )
        self.__anticipation_time = anticipation_time
        self.__overlaying_time = overlaying_time
        self.__tempo_factor = tempo_factor
        self.__attack_duration = attack_duration
        self.__release_duration = release_duration
        self.__crossfade_duration = crossfade_duration
        self.__halved_crossfade_duration = crossfade_duration * 0.5