def render(self, name: str, cadence: old.Cadence) -> subprocess.Popen: seq = [] for chord in cadence: dur = float(chord.delay) if chord.pitch != mel.TheEmptyPitch and bool(chord.pitch): size = len(chord.pitch) for idx, pi in enumerate(chord.pitch): if idx + 1 == size: de = float(dur) else: de = 0 if pi != mel.TheEmptyPitch: if chord.volume: volume = chord.volume else: volume = self.volume tone = midiplug.PyteqTone( ji.JIPitch(pi, multiply=self.CONCERT_PITCH), de, dur, volume=volume, ) else: tone = midiplug.PyteqTone( mel.TheEmptyPitch, de, dur, volume=self.volume ) seq.append(tone) else: seq.append(old.Rest(dur)) pt = midiplug.Pianoteq(tuple(seq), self.available_midi_notes) return pt.export2wav(name, 1, self.preset, self.fxp)
def mk_empty_attack( duration: float, volume: float, frequency: float = 35, hammer_noise: float = 3, impedance: float = 0.3, cutoff: float = 0.3, q_factor: float = 5, string_length: float = 0.8, strike_point: float = 1 / 2, hammer_hard_piano: float = 1, hammer_hard_mezzo: float = 1.5, hammer_hard_forte: float = 2, blooming_energy: float = 0, ) -> midiplug.PyteqTone: """Helps making percussive sounds with Pianoteq.""" return midiplug.PyteqTone( ji.JIPitch(ji.r(1, 1), multiply=frequency), duration, duration, volume=volume, hammer_noise=hammer_noise, impedance=impedance, cutoff=cutoff, q_factor=q_factor, string_length=string_length, strike_point=strike_point, hammer_hard_piano=hammer_hard_piano, hammer_hard_mezzo=hammer_hard_mezzo, hammer_hard_forte=hammer_hard_forte, blooming_energy=blooming_energy, )
def synthesize(self, name: str) -> None: sequence = [] for tone in self: p = tone.pitch d = tone.delay p.multiply = self.concert_pitch d *= 4 sequence.append(midiplug.PyteqTone(p, d, d)) midiplug.Pianoteq(sequence).export2wav(name, preset='"Erard Player"')
def synthesize( self, stretch_factor: float = 1, n_divisions: int = 8, min_tone_size: fractions.Fraction = 0, min_rest_size: fractions.Fraction = fractions.Fraction(1, 10), concert_pitch: float = None, tie_notes: bool = False, remove_rests: bool = False, ) -> None: if not concert_pitch: concert_pitch = self.concert_pitch pitches, delays = self.quantizise( stretch_factor=stretch_factor, n_divisions=n_divisions, min_tone_size=min_tone_size, min_rest_size=min_rest_size, ) melody = old.Melody([old.Tone(p, d) for p, d in zip(pitches, delays)]) if remove_rests: melody = melody.discard_rests() if tie_notes: melody = melody.tie() sequence = [] for tone in melody: p = tone.pitch d = tone.delay p.multiply = concert_pitch d *= 4 sequence.append(midiplug.PyteqTone(p, d, d)) midiplug.Pianoteq(sequence).export2wav("{}_transcription".format( self.name), preset='"Erard Player"')
def render(self, path: str) -> subprocess.Popen: adapted_rhythms = [ rhythm * self.__tempo_factor for rhythm in self.__rhythm ] adapted_rhythms[-1] += self.__overlaying_time melody = old.Melody( tuple( old.Tone(p, r, r, volume=v) for p, r, v in zip( self.__pitches, adapted_rhythms, self.__dynamics))) is_consonant_pitch_per_tone = tuple( self.__is_not_dissonant_pitch_per_tone) spectrum_profile_per_tone = tuple(self.__spectrum_profile_per_tone) if self.convert_dissonant_tones2glissandi: melody = self._convert_dissonant_tones2glissandi(melody) if self.__tremolo is not None: info = self.__tremolo(melody, is_consonant_pitch_per_tone, spectrum_profile_per_tone) melody, is_consonant_pitch_per_tone, spectrum_profile_per_tone = info for modulator in self.modulator: melody = modulator(melody) sequence = [] for tone, is_not_dissonant_pitch, spectrum_profile in zip( melody, is_consonant_pitch_per_tone, spectrum_profile_per_tone): pitch, rhythm, volume, glissando = ( tone.pitch, tone.delay, tone.volume, tone.glissando, ) if pitch.is_empty: tone = pteqer.mk_empty_attack( rhythm, next(self.empty_attack_dynamic_maker)) else: if is_not_dissonant_pitch: parameters = dict(self.parameter_non_dissonant_pitches) else: parameters = dict(self.parameter_dissonant_pitches) for par in parameters: value = parameters[par] if isinstance(value, infit.InfIt): parameters[par] = next(value) elif (isinstance(value, float) or isinstance(value, int) or value is None): parameters[par] = value else: msg = "Unknown value type: {}.".format(type(value)) raise TypeError(msg) if parameters["pinch_harmonic_pedal"] == 1: if parameters["pinch_harmonic_pedal"]: pitch -= ji.r(2, 1) tone = midiplug.PyteqTone( ji.JIPitch(pitch, multiply=globals.CONCERT_PITCH), rhythm, rhythm, volume=volume, glissando=glissando, spectrum_profile_3=spectrum_profile[0], spectrum_profile_5=spectrum_profile[1], spectrum_profile_6=spectrum_profile[0], spectrum_profile_7=spectrum_profile[2], **parameters, ) sequence.append(tone) pteq = midiplug.Pianoteq(tuple(sequence)) return pteq.export2wav(path, preset=self.preset, fxp=self.fxp)