def get_pitches(self, from_pitch: Pitch, to_pitch: Pitch, detune=0.0) -> list: octave_shift = 0 while self._pitches[-1].get_cents_from_a()\ + 1200*octave_shift\ + self._detune\ + detune\ > from_pitch.get_cents_from_a(): octave_shift -= 1 possible_pitches = list() while self._pitches[0].get_cents_from_a()\ + 1200*octave_shift\ + self._detune\ + detune\ < to_pitch.get_cents_from_a(): for pitch in self._pitches: if from_pitch.get_cents_from_a()\ <= pitch.get_cents_from_a()\ + 1200*octave_shift\ + self._detune\ + detune\ <= to_pitch.get_cents_from_a(): possible_pitches.append( pitch.copy(detune=1200 * octave_shift + self._detune + detune)) octave_shift += 1 return possible_pitches
def generate_memory_flush( self, lowest_pitch:Pitch, highest_pitch:Pitch, min_sounds=8, max_sounds=12, sound_play_time=0.2 ) -> np.array: """ Generate series of random frequencies and random length. :lowest_pitch: The lowest pitch :highest_pitch: The highest pitch :min_sounds: Minimal number of sounds in a series. :max_sounds: Maximal number of sounds in a series. :sound_play_time: Length of every sound in seconds. :returns: Output signal. """ output = np.zeros(0) for i in range(random.randint(min_sounds, max_sounds)): output = np.concatenate([ output, self.generate_frequency( random.uniform( lowest_pitch.get_frequency(), highest_pitch.get_frequency() ), sound_play_time ) ]) return output
def __init__(self, scale=Scale('12-TET (A=440Hz)'), lowest_pitch=Pitch(21), highest_pitch=Pitch(108), possible_detune=1.0): self._scale = scale self._lowest_pitch = lowest_pitch self._highest_pitch = highest_pitch self._possible_detune = possible_detune
def __init__(self, scale=IntervalScale('Whole Tone Fractions'), lowest_pitch=Pitch.from_name('C3'), highest_pitch=Pitch.from_name('C5'), possible_detune=0.5): self._scale = scale self._lowest_pitch = lowest_pitch self._highest_pitch = highest_pitch self._possible_detune = possible_detune
def __init__(self, scale=Scale('12-TET (A=440Hz)'), lowest_pitch=Pitch.from_midi(21), highest_pitch=Pitch.from_midi(108), possible_detune=1.0, smallest_interval=Interval.from_name('unison'), largest_interval=Interval.from_name('octave')): self._scale = scale self._lowest_pitch = lowest_pitch self._highest_pitch = highest_pitch self._possible_detune = possible_detune self._smallest_interval = smallest_interval self._largest_interval = largest_interval
def generate_interval(self) -> (Interval, Pitch, Pitch): # Generate first random pitch pitch1 = Pitch.from_frequency( random.uniform(self._lowest_pitch.get_frequency(), self._highest_pitch.get_frequency())) # Generate second random pitch output_interval = random.choice(self._scale.get_intervals()) pitch2 = pitch1.add_interval(output_interval) if pitch2 == Pitch.higher(self._highest_pitch, pitch2): pitch2 = pitch1.copy(detune=-output_interval.get_cents()) if pitch2 == Pitch.lower(self._lowest_pitch, pitch2): raise RuntimeError( '[MicrotonalIntervalGenerator:generate_interval()] ' + 'Could not generate interval! ' + 'Make sure that lowest_pitch is sufficiently lower than highest_pitch!' ) # Return interval and pitches output_pitch1 = Pitch.from_pitch(pitch=Pitch.lower(pitch1, pitch2), detune=random.uniform( -self._possible_detune / 2, self._possible_detune / 2)) output_pitch2 = Pitch.from_pitch(pitch=Pitch.higher(pitch1, pitch2), detune=random.uniform( -self._possible_detune / 2, self._possible_detune / 2)) return output_interval, output_pitch1, output_pitch2
def generate_pitch(self, pitch:Pitch, time:float) -> np.array: """ Generate signal of given length and pitch. :pitch: Pitch of output sound. :time: Length of sound in seconds. :returns: Output signal. """ return self.generate_frequency(pitch.get_frequency(), time)
def generate_interval(self) -> (Interval, Pitch, Pitch): # Generate first random pitch pitch_generator = PitchGenerator(scale=self._scale, lowest_pitch=self._lowest_pitch, highest_pitch=self._highest_pitch, possible_detune=0) pitch1 = pitch_generator.generate_pitch() # Generate second random pitch possible_pitches = list() for pitch in self._scale.get_pitches(from_pitch=self._lowest_pitch, to_pitch=self._highest_pitch): interval = Interval.from_pitches( from_pitch=Pitch.lower(pitch1, pitch), to_pitch=Pitch.higher(pitch1, pitch)) if self._largest_interval.get_cents()\ >= interval.get_cents()\ >= self._smallest_interval.get_cents(): possible_pitches.append(pitch) pitch2 = random.choice(possible_pitches) # Return interval and pitches output_pitch1 = Pitch.from_pitch(pitch=Pitch.lower(pitch1, pitch2), detune=random.uniform( -self._possible_detune / 2, self._possible_detune / 2)) output_pitch2 = Pitch.from_pitch(pitch=Pitch.higher(pitch1, pitch2), detune=random.uniform( -self._possible_detune / 2, self._possible_detune / 2)) output_interval = Interval.from_pitches(from_pitch=output_pitch1, to_pitch=output_pitch2) return output_interval, output_pitch1, output_pitch2
def __init__(self, properties, octave=4): self.name = properties.get('name') self.alternative = properties.get('alt') self.degree = properties.get('deg') self.rank = ( octave * 12 ) + self.degree self.octave = octave octave_offset = octave - _reference_octave() freq = ( _reference_frequency() * power(_interval_ratio(), self.degree) ) frequency_multiplier = power(2, octave_offset) frequency = freq * frequency_multiplier self.pitch = Pitch( float(frequency), # Otherwise sympy goes nuts _reference_frequency() )
class Note: def __init__(self, properties, octave=4): self.name = properties.get('name') self.alternative = properties.get('alt') self.degree = properties.get('deg') self.rank = ( octave * 12 ) + self.degree self.octave = octave octave_offset = octave - _reference_octave() freq = ( _reference_frequency() * power(_interval_ratio(), self.degree) ) frequency_multiplier = power(2, octave_offset) frequency = freq * frequency_multiplier self.pitch = Pitch( float(frequency), # Otherwise sympy goes nuts _reference_frequency() ) def describe(self): return ( "Note(name: {}, alt: {}, octave: {}, degree: {}, {})" ).format( self.name, self.alternative if self.alternative else '-', self.octave, self.degree, self.pitch.describe() ) def __repr__(self): return 'Note({})'.format(self.name)
def highest_pitch_changed(self): self.exercise.set_highest_pitch( Pitch.from_name(self.setting_window.get_setting("highest_pitch")) )
def __init__(self, scale_type=None): """ Musical scale interpreted as the list of musical pitches. """ self._pitches = list() self._detune = 0.0 if scale_type == None: pass elif scale_type == '12-TET (A=440Hz)': self._pitches.append(Pitch.from_midi(60)) self._pitches.append(Pitch.from_midi(61)) self._pitches.append(Pitch.from_midi(62)) self._pitches.append(Pitch.from_midi(63)) self._pitches.append(Pitch.from_midi(64)) self._pitches.append(Pitch.from_midi(65)) self._pitches.append(Pitch.from_midi(66)) self._pitches.append(Pitch.from_midi(67)) self._pitches.append(Pitch.from_midi(68)) self._pitches.append(Pitch.from_midi(69)) self._pitches.append(Pitch.from_midi(70)) self._pitches.append(Pitch.from_midi(71)) elif scale_type == '24-TET (A=440Hz)': self._pitches.append(Pitch.from_midi(60)) self._pitches.append(Pitch.from_midi(60, 50)) self._pitches.append(Pitch.from_midi(61)) self._pitches.append(Pitch.from_midi(61, 50)) self._pitches.append(Pitch.from_midi(62)) self._pitches.append(Pitch.from_midi(62, 50)) self._pitches.append(Pitch.from_midi(63)) self._pitches.append(Pitch.from_midi(63, 50)) self._pitches.append(Pitch.from_midi(64)) self._pitches.append(Pitch.from_midi(64, 50)) self._pitches.append(Pitch.from_midi(65)) self._pitches.append(Pitch.from_midi(65, 50)) self._pitches.append(Pitch.from_midi(66)) self._pitches.append(Pitch.from_midi(66, 50)) self._pitches.append(Pitch.from_midi(67)) self._pitches.append(Pitch.from_midi(67, 50)) self._pitches.append(Pitch.from_midi(68)) self._pitches.append(Pitch.from_midi(68, 50)) self._pitches.append(Pitch.from_midi(69)) self._pitches.append(Pitch.from_midi(69, 50)) self._pitches.append(Pitch.from_midi(70)) self._pitches.append(Pitch.from_midi(70, 50)) self._pitches.append(Pitch.from_midi(71)) self._pitches.append(Pitch.from_midi(71, 50)) elif scale_type == '31-TET (A=440Hz)': self._pitches.append(Pitch.from_midi(57)) self._pitches.append(Pitch.from_midi(57, 1 * 38.71)) self._pitches.append(Pitch.from_midi(57, 2 * 38.71)) self._pitches.append(Pitch.from_midi(57, 3 * 38.71)) self._pitches.append(Pitch.from_midi(57, 4 * 38.71)) self._pitches.append(Pitch.from_midi(57, 5 * 38.71)) self._pitches.append(Pitch.from_midi(57, 6 * 38.71)) self._pitches.append(Pitch.from_midi(57, 7 * 38.71)) self._pitches.append(Pitch.from_midi(57, 8 * 38.71)) self._pitches.append(Pitch.from_midi(57, 9 * 38.71)) self._pitches.append(Pitch.from_midi(57, 10 * 38.71)) self._pitches.append(Pitch.from_midi(57, 11 * 38.71)) self._pitches.append(Pitch.from_midi(57, 12 * 38.71)) self._pitches.append(Pitch.from_midi(57, 13 * 38.71)) self._pitches.append(Pitch.from_midi(57, 14 * 38.71)) self._pitches.append(Pitch.from_midi(57, 15 * 38.71)) self._pitches.append(Pitch.from_midi(57, 16 * 38.71)) self._pitches.append(Pitch.from_midi(57, 17 * 38.71)) self._pitches.append(Pitch.from_midi(57, 18 * 38.71)) self._pitches.append(Pitch.from_midi(57, 19 * 38.71)) self._pitches.append(Pitch.from_midi(57, 20 * 38.71)) self._pitches.append(Pitch.from_midi(57, 21 * 38.71)) self._pitches.append(Pitch.from_midi(57, 22 * 38.71)) self._pitches.append(Pitch.from_midi(57, 23 * 38.71)) self._pitches.append(Pitch.from_midi(57, 24 * 38.71)) self._pitches.append(Pitch.from_midi(57, 25 * 38.71)) self._pitches.append(Pitch.from_midi(57, 26 * 38.71)) self._pitches.append(Pitch.from_midi(57, 27 * 38.71)) self._pitches.append(Pitch.from_midi(57, 28 * 38.71)) self._pitches.append(Pitch.from_midi(57, 29 * 38.71)) self._pitches.append(Pitch.from_midi(57, 30 * 38.71)) elif scale_type == 'Pythagorean (C-based) (A=440Hz)': self._pitches.append(Pitch.from_midi(60, -5.87)) self._pitches.append(Pitch.from_midi(61, 7.82)) self._pitches.append(Pitch.from_midi(62, -1.96)) self._pitches.append(Pitch.from_midi(63, 11.73)) self._pitches.append(Pitch.from_midi(64, 1.96)) self._pitches.append(Pitch.from_midi(65, 15.64)) self._pitches.append(Pitch.from_midi(66, 5.87)) self._pitches.append(Pitch.from_midi(67, -3.91)) self._pitches.append(Pitch.from_midi(68, 9.78)) self._pitches.append(Pitch.from_midi(69)) self._pitches.append(Pitch.from_midi(70, 13.69)) self._pitches.append(Pitch.from_midi(71, 3.91)) elif scale_type == 'Just (C-based) (A=440Hz)': self._pitches.append(Pitch.from_midi(60, 15.64)) self._pitches.append(Pitch.from_midi(61, 27.37)) self._pitches.append(Pitch.from_midi(62, 19.55)) self._pitches.append(Pitch.from_midi(63, 31.28)) self._pitches.append(Pitch.from_midi(64, 1.96)) self._pitches.append(Pitch.from_midi(65, 13.69)) self._pitches.append(Pitch.from_midi(66, 5.87)) self._pitches.append(Pitch.from_midi(67, 17.60)) self._pitches.append(Pitch.from_midi(68, 29.33)) self._pitches.append(Pitch.from_midi(69)) self._pitches.append(Pitch.from_midi(70, 11.73)) self._pitches.append(Pitch.from_midi(71, 3.91)) elif scale_type == 'Quarter-comma meantone (C-based) (A=440Hz)': self._pitches.append(Pitch.from_midi(60, 10.26)) self._pitches.append(Pitch.from_midi(61, -13.68)) self._pitches.append(Pitch.from_midi(62, 3.42)) self._pitches.append(Pitch.from_midi(63, -20.53)) self._pitches.append(Pitch.from_midi(64, -3.42)) self._pitches.append(Pitch.from_midi(65, -27.37)) self._pitches.append(Pitch.from_midi(66, -10.26)) self._pitches.append(Pitch.from_midi(67, 6.84)) self._pitches.append(Pitch.from_midi(68, -17.11)) self._pitches.append(Pitch.from_midi(69)) self._pitches.append(Pitch.from_midi(70, 23.95)) self._pitches.append(Pitch.from_midi(71, -6.84)) elif scale_type == 'Bach\'s (Werckmeister III) (A=440Hz)': self._pitches.append(Pitch.from_midi(60, 11.73)) self._pitches.append(Pitch.from_midi(61, 1.96)) self._pitches.append(Pitch.from_midi(62, 3.91)) self._pitches.append(Pitch.from_midi(63, 5.87)) self._pitches.append(Pitch.from_midi(64, 1.96)) self._pitches.append(Pitch.from_midi(65, 9.78)) self._pitches.append(Pitch.from_midi(66)) self._pitches.append(Pitch.from_midi(67, 7.82)) self._pitches.append(Pitch.from_midi(68, 3.91)) self._pitches.append(Pitch.from_midi(69)) self._pitches.append(Pitch.from_midi(70, 7.82)) self._pitches.append(Pitch.from_midi(71, 3.91)) # Raise error else: raise RuntimeError( '[Scale::__init__()] Unknown scale type "'\ + scale_type\ + '"!' )