Example #1
0
def make_part_tuplet():
    # create a part
    part = score.Part('My Part')

    # create contents
    divs = 12
    ts = score.TimeSignature(3, 4)
    page1 = score.Page(1)
    system1 = score.System(1)

    note1 = score.Note(id='n0', step='A', octave=4, voice=1, staff=1)
    rest1 = score.Rest(voice=1, staff=1)
    note2 = score.Note(id='n2', step='C', octave=4, voice=1, staff=1)
    rest2 = score.Rest(id='r0', voice=1, staff=1)
    
    # and add the contents to the part:
    part.set_quarter_duration(0, divs)
    part.add(ts, 0)
    part.add(page1, 0)
    part.add(system1, 0)
    part.add(note1, 0, 8)
    part.add(rest1, 8, 16)
    part.add(note2, 16, 24)
    part.add(rest2, 24, 36)

    score.add_measures(part)
    score.find_tuplets(part)
    score.set_end_times(part)

    return part
Example #2
0
def _handle_new_page(position, part, ongoing):
    if 'page' in ongoing:
        if position == 0:
            # ignore non-informative new-page at start of score
            return

        part.add(ongoing['page'], None, position)
        page_nr = ongoing['page'].number + 1
    else:
        page_nr = 1

    page = score.Page(page_nr)
    part.add(page, position)
    ongoing['page'] = page
Example #3
0
    def test_export_import_pprint(self):
        # create a part
        part1 = score.Part('My Part')

        # create contents
        divs = 10
        ts = score.TimeSignature(3, 4)
        page1 = score.Page(1)
        system1 = score.System(1)
        measure1 = score.Measure(number=1)
        note1 = score.Note(step='A', octave=4, voice=1, staff=1)
        rest1 = score.Rest(voice=1, staff=1)
        note2 = score.Note(step='C', octave=5, alter=-1, voice=2, staff=1)
        
        # and add the contents to the part:
        part1.set_quarter_duration(0, divs)
        part1.add(ts, 0)
        part1.add(measure1, 0, 30)
        part1.add(page1, 0)
        part1.add(system1, 0)
        part1.add(note1, 0, 15)
        part1.add(rest1, 15, 30)
        part1.add(note2, 0, 30)
        
        score.set_end_times(part1)
        
        # pretty print the part
        pstring1 = part1.pretty()

        with TemporaryFile() as f:
            # save part to musicxml
            save_musicxml(part1, f)
            f.flush()
            f.seek(0)
            # load part from musicxml
            part2 = load_musicxml(f)

        # pretty print saved/loaded part:
        pstring2 = part2.pretty()

        # test pretty printed strings for equality
        equal = pstring1 == pstring2

        if not equal:
            show_diff(pstring1, pstring2)
        msg = 'Exported and imported score does not yield identical pretty printed representations'
        self.assertTrue(equal, msg)
Example #4
0
def make_part_slur():
    # create a part
    part = score.Part('My Part')
    # create contents
    divs = 12
    ts = score.TimeSignature(3, 4)
    page1 = score.Page(1)
    system1 = score.System(1)

    note0 = score.Note(id='n0', step='A', octave=4, voice=1, staff=1)
    note1 = score.Note(id='n1', step='A', octave=4, voice=1, staff=1)
    note2 = score.Note(id='n2', step='A', octave=4, voice=1, staff=1)
    note3 = score.Note(id='n3', step='A', octave=4, voice=1, staff=1)

    note4 = score.Note(id='n4', step='A', octave=3, voice=2, staff=1)
    note5 = score.Note(id='n5', step='A', octave=3, voice=2, staff=1)

    slur1 = score.Slur(start_note=note0, end_note=note5)
    slur2 = score.Slur(start_note=note4, end_note=note3)
    
    # and add the contents to the part:
    part.set_quarter_duration(0, divs)
    part.add(ts, 0)
    part.add(page1, 0)
    part.add(system1, 0)
    part.add(note0, 0, 12)
    part.add(note1, 12, 24)
    part.add(note2, 24, 36)
    part.add(note3, 36, 48)
    part.add(note4, 0, 6)
    part.add(note5, 6, 33)
    part.add(slur1, 
                      slur1.start_note.start.t,
                      slur1.end_note.end.t)
    part.add(slur2, 
                      slur2.start_note.start.t,
                      slur2.end_note.end.t)

    score.add_measures(part)
    score.tie_notes(part)
    score.set_end_times(part)
    return part