def timeslot_pitch_to_field_cell(timeslot, pitch): from manifolds.etc.pitch import pitch_fields if not isinstance(timeslot, int): raise ValueError pitch = pitchtools.NamedPitch(pitch) field = pitch_fields[timeslot % len(pitch_fields)] direction = timeslot_to_direction(timeslot) pitch = pitch.pitch_number cell = field_direction_pitch_to_cell(field, direction, pitch) return cell
def make_prominence_between(start_field, start_direction, start_pitch, stop_field, stop_direction, stop_pitch, count): '''Find cell in start_segmented_field closest to start_harmonic_pitch. Call this start_cell. Find cell in stop_segmented_field closest to stop_harmonic_pitch. Call this stop_cell. Make prominence between start_cell and stop_cell. Return prominence as list of (field, index, cell) triples. So [('R1', 2, (3, 5, 11, 13, 15.5, 17.5, 19, 20)), ('R1', 3, (26, 32, 33, 34)), ...] Returned list of tuples will always have length two or greater. ''' # check input assert isinstance(count, int) assert 0 <= count # empty list on zero count if count == 0: return [] # process start field segmented_start_field = partition_to_avoid_octave_adjacencies( start_field, start_direction) start_cell = field_direction_pitch_to_cell( start_field, start_direction, start_pitch) start_cell_index = segmented_start_field.index(start_cell) start_field_number = field_to_field_number(start_field) start_field_letter = _direction_to_letter(start_direction) start_id = '%s%s' % (start_field_letter, start_field_number) # process stop field segmented_stop_field = partition_to_avoid_octave_adjacencies( stop_field, stop_direction) stop_cell = field_direction_pitch_to_cell( stop_field, stop_direction, stop_pitch) stop_cell_index = segmented_stop_field.index(stop_cell) stop_field_number = field_to_field_number(stop_field) stop_field_letter = _direction_to_letter(stop_direction) stop_id = '%s%s' % (stop_field_letter, stop_field_number) # halve start field start_indices = range(len(segmented_start_field)) low_start_cells = segmented_start_field[:start_cell_index] low_start_indices = start_indices[:start_cell_index] high_start_cells = segmented_start_field[start_cell_index:] high_start_indices = start_indices[start_cell_index:] pairs = zip(low_start_indices, low_start_cells) low_start_triples = [(start_id, index, cell) for index, cell in pairs] pairs = zip(high_start_indices, high_start_cells) high_start_triples = [(start_id, index, cell) for index, cell in pairs] # halve stop field stop_indices = range(len(segmented_stop_field)) low_stop_cells = segmented_stop_field[:stop_cell_index+1] low_stop_indices = stop_indices[:stop_cell_index+1] high_stop_cells = segmented_stop_field[stop_cell_index+1:] high_stop_indices = stop_indices[stop_cell_index+1:] pairs = zip(low_stop_indices, low_stop_cells) low_stop_triples = [(stop_id, index, cell) for index, cell in pairs] pairs = zip(high_stop_indices, high_stop_cells) high_stop_triples = [(stop_id, index, cell) for index, cell in pairs] # build period begin_period = high_start_triples + low_stop_triples end_period = high_stop_triples + low_start_triples # build prominence prominence = [] # count == 1 prominence.extend(begin_period) # 1 < count for period in range(count - 1): prominence.extend(end_period) prominence.extend(begin_period) # return prominence return prominence