def test_section_index_to_polar_value_01(): assert section_index_to_polar_value(0) == 13 assert section_index_to_polar_value(1) == 15 assert section_index_to_polar_value(2) == 21 assert section_index_to_polar_value(3) == 10
def make_cells_with_prominences_score(): from manifolds.etc.pitch import prominent_section_numbers from manifolds.etc.pitch import sequence_with_prominences as sections from manifolds.etc.pitch._helpers import field_id_to_segmented_field from manifolds.etc.pitch._helpers import section_index_to_polar_value assert len(sections) == 46 score, treble, bass = make_piano_staff() prominence_lengths = _prominence_lengths() duration = Fraction(1, 16) output_cells = [] cell_index_in_score = 0 ## enumerate forty-six separate sections for section_index, section in enumerate(sections): cur_polar_value = section_index_to_polar_value(section_index) next_polar_value = section_index_to_polar_value(section_index + 1) prominence_length = prominence_lengths[section_index] first_prominent_triple = len(section) - prominence_length - 1 cell_number_in_section = 1 first_field_id_in_prominence = None second_field_id_in_prominence = None for triple_index, triple in enumerate(section): section_number = section_index + 1 field_id, middle, cell = triple segmented_field = field_id_to_segmented_field(field_id) cell_number_in_field = segmented_field.index(cell) + 1 if 0 < prominence_length and first_prominent_triple <= triple_index: if cell_number_in_prominence is None: cell_number_in_prominence = 1 first_field_id_in_prominence = field_id else: cell_number_in_prominence += 1 if not field_id == first_field_id_in_prominence: second_field_id_in_prominence = field_id else: cell_number_in_prominence = None measure = AnonymousMeasure([]) notes = [Note(pitch, duration) for pitch in cell] measure.extend(notes) if triple_index + 1 == len(section): measure.barline.kind = '||' if cell_number_in_prominence is not None: measure.notehead.style = 'harmonic' for leaf in measure.leaves: leaf.notehead.color = 'red' rest_measure = clone.unspan([measure])[0] for i, note in enumerate(rest_measure): rest_measure[i] = Rest(note.duration.written) pitches = [note.pitch for note in notes] cell_clef = pitchtools.suggest_clef(pitches) if cell_clef == Clef('treble'): treble.append(measure) bass.append(rest_measure) else: treble.append(rest_measure) bass.append(measure) if 26 < max(cell): octavation = Octavation(measure[:]) octavation.start = 1 notated_polar_value = cur_polar_value if cell_number_in_prominence is not None: if field_id == second_field_id_in_prominence: notated_polar_value = next_polar_value polar_clef = pitchtools.suggest_clef([Pitch(notated_polar_value)]) if polar_clef == cell_clef: chord = Chord(measure[0]) notehead = NoteHead(None, notated_polar_value) chord.append(notehead) else: note = Note(rest_measure[0]) note.pitch = notated_polar_value notehead = note.notehead notehead.style = 'harmonic' notehead.color = 'blue' first_leaf = bass[-1].leaves[0] if cell_number_in_prominence is not None: first_markup = r'\small \line { %s / %s-%s-%s }' % ( cell_index_in_score, section_number, first_prominent_triple + 1, cell_number_in_prominence) else: first_markup = r'\small \line { %s / %s-%s }' % ( cell_index_in_score, section_number, cell_number_in_section) first_leaf.markup.down.append(first_markup) second_markup = r'\small \line { %s-%s \with-color #blue (%s) }' % ( field_id, cell_number_in_field, notated_polar_value) first_leaf.markup.down.append(second_markup) ## make output to write to disk output_cell = ( cell_index_in_score, field_id, cell_number_in_field, cell, section_number, cell_number_in_section, cell_number_in_prominence, notated_polar_value) output_cells.append(output_cell) cell_number_in_section += 1 cell_index_in_score += 1 lower_bass_markup_blocks(bass) front, back = Fraction(1, 16), Fraction(1, 32) layout.insert_measure_padding(score, front, back) section_lengths = [len(section) for section in sections] label_sections_in_treble_in_blue(treble, section_lengths) treble.text.X_offset = 'center' treble.text.self_alignment_X = 'center' bass.text.staff_padding = 4 layout.line_break_every_prolated(treble, Fraction(54, 16)) layout.line_break_every_prolated(bass, Fraction(54, 16)) staves = StaffAlignmentOffsets(0, -10) systems = SystemYOffsets(45, 5) positioning = FixedStaffPositioning(systems, staves) layout.apply_fixed_staff_positioning(treble, positioning) score.rest.transparent = True score.formatter.number.measures = 'comment' return score, output_cells
def test_section_index_to_polar_value_02(): assert section_index_to_polar_value(23) == 13 assert section_index_to_polar_value(24) == 15 assert section_index_to_polar_value(25) == 21 assert section_index_to_polar_value(26) == 10