Пример #1
0
def composificate(tracks1, tracks2):
    """Extends tracks1 (presumed to be some sort of percussion) to the length of
    track2. Returns a Composition."""
    compo = Composition()
    #Extend each track1 to the length of the corresponding track2
    ntracks = []
    if len(tracks1) < len(tracks2):
        for track in tracks1:
            idx = tracks1.index(track)
            track = extend_track(track, len(tracks2[idx]))
            ntracks.append(track)
    else:
        ntracks = tracks1
    percus = sum_tracks(ntracks)
    melody = sum_tracks(tracks2)

    piano = MidiInstrument()
    piano.name = 'Acoustic Grand Piano'
    percussion = MidiInstrument()
    percussion.name = 'Woodblock'

    percus.instrument = percussion
    melody.instrument = piano
    compo.add_track(percus)
    compo.add_track(melody)
    return compo
Пример #2
0
def composificate(tracks1, tracks2):
    """Extends tracks1 (presumed to be some sort of percussion) to the length of
    track2. Returns a Composition."""
    compo = Composition()
    #Extend each track1 to the length of the corresponding track2
    ntracks = []
    if len(tracks1) < len(tracks2):
        for track in tracks1:
            idx = tracks1.index(track)
            track = extend_track(track, len(tracks2[idx]))
            ntracks.append(track)
    else:
        ntracks = tracks1
    percus = sum_tracks(ntracks)
    melody = sum_tracks(tracks2)

    piano = MidiInstrument()
    piano.name = 'Acoustic Grand Piano'
    percussion = MidiInstrument()
    percussion.name = 'Woodblock'
    
    percus.instrument = percussion
    melody.instrument = piano
    compo.add_track(percus)
    compo.add_track(melody)
    return compo
Пример #3
0
def load_entry(db, doc_id=0):
    '''
    Re-instantiates entry as a JazzLick object given TinyDB doc_id
    '''
    x = Track_from_list(ast.literal_eval(db.get(doc_id=doc_id)['passage'])[1])

    c = Composition()
    x.bars = Bars_from_list(x.bars)
    c.add_track(x)

    j = JazzLick(c, passage_track=0, chords=db.get(doc_id=doc_id)['chords'])
            
    return j
Пример #4
0
def main():
    comp = Composition()
    with open('out.txt', 'r') as f:
        lines = f.readlines()
        for line in lines:
            tb = TrackBuilder()
            symbols = line.rstrip().split(' ')[1:]
            print(symbols)
            for symbol in symbols:
                tb.add_symbol(symbol)
            track = tb.flush()
            comp.add_track(track)
    fluidsynth.init('../sfs/soundfont.sf2', 'alsa')
    fluidsynth.play_Composition(comp)
Пример #5
0
def rebuild_composition(old, xylo, cutoff):
    lowest = Note.__int__(Note('C', 8))
    highest = Note.__int__(Note('C', 0))
    new = Composition()
    for i in old.selected_tracks:
        t = Track()
        t.instrument = xylo
        for bar in old[i]:
            b = Bar()
            b.key.name = bar.key.name
            b.set_meter(bar.meter)
            # note value per beat == the denominator in time signature
            dem = b.meter[1]
            for lst in bar:
                value = lst[1]
                if (is_garbage(value, dem, cutoff[old.selected_tracks.index(i)])):
                    continue
                # do not include lists without notes
                if (not lst[2]):
                    continue
                nc = NoteContainer()
                for note in lst[2]:
                    if (Note.__int__(note) < lowest): lowest = Note.__int__(note)
                    if (Note.__int__(note) > highest): highest = Note.__int__(note)
                    nc + note
                b.place_notes(nc, value)
            t.add_bar(b)
        new.add_track(t)
    # can't do the transposing until all notes in all tracks have been
    # compared against lowest and highest, which is why it is done here
    n1 = Note()
    n2 = Note()
    low = n1.from_int(lowest)
    high = n2.from_int(highest)
    # print("lowest and highest notes:", low, high)
    if (not xylo.notes_in_range([low, high])):
        new = transposer(new, lowest, highest, xylo)
    return new
Пример #6
0
class test_LilyPond(unittest.TestCase):

    def setUp(self):
        self.commonbar = Bar()
        self.ebar = Bar('E', (4, 4))
        self.fbar = Bar('F', (6, 8))
        self.tbar = Bar('C', (4, 4))
        self.mbar = Bar('C', (4, 4))
        self.a_minor_bar = Bar('a', (4, 4))
        self.b_flat_minor_bar = Bar('bb', (4, 4))
        self.f_sharp_minor_bar = Bar('f#', (4, 4))
        for y in [self.commonbar, self.ebar, self.fbar]:
            map(lambda x: y + x, ['C', 'E', 'G', 'B'])
        map(lambda x: self.tbar.place_notes(NoteContainer(x), 6), [
            'C',
            'E',
            'G',
            'B',
            'C',
            'E',
            ])
        map(lambda x: self.mbar.place_notes(NoteContainer(x), 4), ['C', 'E'])
        map(lambda x: self.mbar.place_notes(NoteContainer(x), 6), ['G', 'B', 'C'
            ])
        self.track1 = Track()
        self.track1 + self.commonbar
        self.track2 = Track()
        self.track2 + self.commonbar
        self.track2 + self.ebar
        self.composition1 = Composition()
        self.composition1.add_track(self.track1)
        self.composition2 = Composition()
        self.composition2.add_track(self.track1)
        self.composition2.add_track(self.track2)

    def test_from_Note(self):
        self.assertEqual(LilyPond.from_Note(Note('C'), standalone=False), "c'")
        self.assertEqual(LilyPond.from_Note(Note('C#'), standalone=False),
                         "cis'")
        self.assertEqual(LilyPond.from_Note(Note('C##'), standalone=False),
                         "cisis'")
        self.assertEqual(LilyPond.from_Note(Note('Cb'), standalone=False),
                         "ces'")
        self.assertEqual(LilyPond.from_Note(Note('Cbb'), standalone=False),
                         "ceses'")
        self.assertEqual(LilyPond.from_Note(Note('C', 0), standalone=False),
                         'c,,,')
        self.assertEqual(LilyPond.from_Note(Note('C', 1), standalone=False),
                         'c,,')
        self.assertEqual(LilyPond.from_Note(Note('C', 2), standalone=False),
                         'c,')
        self.assertEqual(LilyPond.from_Note(Note('C', 3), standalone=False), 'c'
                         )
        self.assertEqual(LilyPond.from_Note(Note('C', 4), standalone=False),
                         "c'")
        self.assertEqual(LilyPond.from_Note(Note('C', 5), standalone=False),
                         "c''")
        self.assertEqual(LilyPond.from_Note(Note('C', 6), standalone=False),
                         "c'''")
        self.assertEqual(LilyPond.from_Note(Note('C', 7), standalone=False),
                         "c''''")

    def test_from_NoteContainer(self):
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'),
                         standalone=False), "c'")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 4,
                         standalone=False), "c'4")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer(['C', 'E']),
                         standalone=False), "<c' e'>")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer(['C', 'E']),
                         4, standalone=False), "<c' e'>4")

        # issue #37

        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 16,
                         standalone=False), "c'16")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 16.0,
                         standalone=False), "c'16")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'),
                         value.dots(16), standalone=False), "c'16.")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 0.25,
                         standalone=False), "c'\\longa")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 0.5,
                         standalone=False), "c'\\breve")

    def test_from_Bar(self):
        self.assertEqual(LilyPond.from_Bar(self.commonbar),
                         "{ \\time 4/4 \\key c \\major c'4 e'4 g'4 b'4 }")
        self.assertEqual(LilyPond.from_Bar(self.ebar),
                         "{ \\time 4/4 \\key e \\major c'4 e'4 g'4 b'4 }")
        self.assertEqual(LilyPond.from_Bar(self.fbar),
                         "{ \\time 6/8 \\key f \\major c'8 e'8 g'8 b'8 }")
        self.assertEqual(LilyPond.from_Bar(self.a_minor_bar),
                         "{ \\time 4/4 \\key a \\minor }")
        self.assertEqual(LilyPond.from_Bar(self.b_flat_minor_bar),
                         "{ \\time 4/4 \\key bes \\minor }")
        self.assertEqual(LilyPond.from_Bar(self.f_sharp_minor_bar),
                         "{ \\time 4/4 \\key fis \\minor }")

    def test_from_Track(self):
        self.assertEqual(LilyPond.from_Track(self.track1),
                         "{ { c'4 e'4 g'4 b'4 } }")
        self.assertEqual(LilyPond.from_Track(self.track2),
                         "{ { c'4 e'4 g'4 b'4 } { \\key e \\major c'4 e'4 g'4 b'4 } }"
                         )

    def test_from_Composition(self):
        self.assertEqual(LilyPond.from_Composition(self.composition1),
                         '\\header { title = "Untitled" composer = "" opus = "" } { { c\'4 e\'4 g\'4 b\'4 } }'
                         )
        self.assertEqual(LilyPond.from_Composition(self.composition2),
                         '\\header { title = "Untitled" composer = "" opus = "" } { { c\'4 e\'4 g\'4 b\'4 } } { { c\'4 e\'4 g\'4 b\'4 } { \\key e \\major c\'4 e\'4 g\'4 b\'4 } }'
                         )

    def test_from_Suite(self):
        LilyPond.from_Suite(None)

    def test_dotted_notes(self):
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'),
                         value.dots(8), standalone=False), "c'8.")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'),
                         value.dots(4, 2), standalone=False), "c'4..")

    def test_to_pdf(self):
        self.assert_(LilyPond.to_pdf('{ %s }'
                      % LilyPond.from_NoteContainer(NoteContainer('C'),
                     value.dots(8)), 'pdftest first test'))
        self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.tbar), 'pdftest2'))
        self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.mbar), 'pdftest3'))

    def test_to_png(self):
        self.assert_(LilyPond.to_png('{ %s }'
                      % LilyPond.from_NoteContainer(NoteContainer('C'),
                     value.dots(8)), 'pn1'))
        self.assert_(LilyPond.to_png(LilyPond.from_Bar(self.tbar), 'pn2'))
        self.assert_(LilyPond.to_png(LilyPond.from_Bar(self.mbar), 'pn3'))
Пример #7
0
def from_Track(track):
    c = Composition()
    c.add_track(track)
    return _composition2musicxml(c).toprettyxml()
Пример #8
0
def from_Bar(bar):
    c = Composition()
    t = Track()
    t.add_bar(bar)
    c.add_track(t)
    return _composition2musicxml(c).toprettyxml()
Пример #9
0
class test_LilyPond(unittest.TestCase):
    def setUp(self):
        # LilyPond output files are created in current working directory
        self.tempdir = tempfile.mkdtemp()
        self.oldcwd = os.getcwd()
        os.chdir(self.tempdir)

        self.commonbar = Bar()
        self.ebar = Bar("E", (4, 4))
        self.fbar = Bar("F", (6, 8))
        self.tbar = Bar("C", (4, 4))
        self.mbar = Bar("C", (4, 4))
        self.a_minor_bar = Bar("a", (4, 4))
        self.b_flat_minor_bar = Bar("bb", (4, 4))
        self.f_sharp_minor_bar = Bar("f#", (4, 4))
        for y in [self.commonbar, self.ebar, self.fbar]:
            list(map(lambda x: y + x, ["C", "E", "G", "B"]))
        for x in ["C", "E", "G", "B", "C", "E"]:
            self.tbar.place_notes(NoteContainer(x), 6)
        for x in ["C", "E"]:
            self.mbar.place_notes(NoteContainer(x), 4)
        for x in ["G", "B", "C"]:
            self.mbar.place_notes(NoteContainer(x), 6)
        self.track1 = Track()
        self.track1 + self.commonbar
        self.track2 = Track()
        self.track2 + self.commonbar
        self.track2 + self.ebar
        self.composition1 = Composition()
        self.composition1.add_track(self.track1)
        self.composition2 = Composition()
        self.composition2.add_track(self.track1)
        self.composition2.add_track(self.track2)

    def tearDown(self):
        os.chdir(self.oldcwd)
        shutil.rmtree(self.tempdir)

    def test_from_Note(self):
        self.assertEqual(LilyPond.from_Note(Note("C"), standalone=False), "c'")
        self.assertEqual(LilyPond.from_Note(Note("C#"), standalone=False),
                         "cis'")
        self.assertEqual(LilyPond.from_Note(Note("C##"), standalone=False),
                         "cisis'")
        self.assertEqual(LilyPond.from_Note(Note("Cb"), standalone=False),
                         "ces'")
        self.assertEqual(LilyPond.from_Note(Note("Cbb"), standalone=False),
                         "ceses'")
        self.assertEqual(LilyPond.from_Note(Note("C", 0), standalone=False),
                         "c,,,")
        self.assertEqual(LilyPond.from_Note(Note("C", 1), standalone=False),
                         "c,,")
        self.assertEqual(LilyPond.from_Note(Note("C", 2), standalone=False),
                         "c,")
        self.assertEqual(LilyPond.from_Note(Note("C", 3), standalone=False),
                         "c")
        self.assertEqual(LilyPond.from_Note(Note("C", 4), standalone=False),
                         "c'")
        self.assertEqual(LilyPond.from_Note(Note("C", 5), standalone=False),
                         "c''")
        self.assertEqual(LilyPond.from_Note(Note("C", 6), standalone=False),
                         "c'''")
        self.assertEqual(LilyPond.from_Note(Note("C", 7), standalone=False),
                         "c''''")

    def test_from_NoteContainer(self):
        self.assertEqual(
            LilyPond.from_NoteContainer(NoteContainer("C"), standalone=False),
            "c'")
        self.assertEqual(
            LilyPond.from_NoteContainer(NoteContainer("C"),
                                        4,
                                        standalone=False), "c'4")
        self.assertEqual(
            LilyPond.from_NoteContainer(NoteContainer(["C", "E"]),
                                        standalone=False),
            "<c' e'>",
        )
        self.assertEqual(
            LilyPond.from_NoteContainer(NoteContainer(["C", "E"]),
                                        4,
                                        standalone=False),
            "<c' e'>4",
        )

        # issue #37

        self.assertEqual(
            LilyPond.from_NoteContainer(NoteContainer("C"),
                                        16,
                                        standalone=False),
            "c'16",
        )
        self.assertEqual(
            LilyPond.from_NoteContainer(NoteContainer("C"),
                                        16.0,
                                        standalone=False),
            "c'16",
        )
        self.assertEqual(
            LilyPond.from_NoteContainer(NoteContainer("C"),
                                        value.dots(16),
                                        standalone=False),
            "c'16.",
        )
        self.assertEqual(
            LilyPond.from_NoteContainer(NoteContainer("C"),
                                        0.25,
                                        standalone=False),
            "c'\\longa",
        )
        self.assertEqual(
            LilyPond.from_NoteContainer(NoteContainer("C"),
                                        0.5,
                                        standalone=False),
            "c'\\breve",
        )

    def test_from_Bar(self):
        self.assertEqual(
            LilyPond.from_Bar(self.commonbar),
            "{ \\time 4/4 \\key c \\major c'4 e'4 g'4 b'4 }",
        )
        self.assertEqual(
            LilyPond.from_Bar(self.ebar),
            "{ \\time 4/4 \\key e \\major c'4 e'4 g'4 b'4 }",
        )
        self.assertEqual(
            LilyPond.from_Bar(self.fbar),
            "{ \\time 6/8 \\key f \\major c'8 e'8 g'8 b'8 }",
        )
        self.assertEqual(LilyPond.from_Bar(self.a_minor_bar),
                         "{ \\time 4/4 \\key a \\minor }")
        self.assertEqual(LilyPond.from_Bar(self.b_flat_minor_bar),
                         "{ \\time 4/4 \\key bes \\minor }")
        self.assertEqual(
            LilyPond.from_Bar(self.f_sharp_minor_bar),
            "{ \\time 4/4 \\key fis \\minor }",
        )

    def test_from_Track(self):
        self.assertEqual(LilyPond.from_Track(self.track1),
                         "{ { c'4 e'4 g'4 b'4 } }")
        self.assertEqual(
            LilyPond.from_Track(self.track2),
            "{ { c'4 e'4 g'4 b'4 } { \\key e \\major c'4 e'4 g'4 b'4 } }",
        )

    def test_from_Composition(self):
        self.assertEqual(
            LilyPond.from_Composition(self.composition1),
            '\\header { title = "Untitled" composer = "" opus = "" } { { c\'4 e\'4 g\'4 b\'4 } }',
        )
        self.assertEqual(
            LilyPond.from_Composition(self.composition2),
            "\\header { title = \"Untitled\" composer = \"\" opus = \"\" } { { c'4 e'4 g'4 b'4 } } { { c'4 e'4 g'4 b'4 } { \\key e \\major c'4 e'4 g'4 b'4 } }",
        )

    def test_from_Suite(self):
        LilyPond.from_Suite(None)

    def test_dotted_notes(self):
        self.assertEqual(
            LilyPond.from_NoteContainer(NoteContainer("C"),
                                        value.dots(8),
                                        standalone=False),
            "c'8.",
        )
        self.assertEqual(
            LilyPond.from_NoteContainer(NoteContainer("C"),
                                        value.dots(4, 2),
                                        standalone=False),
            "c'4..",
        )

    def test_to_pdf(self):
        self.assertTrue(
            LilyPond.to_pdf(
                "{ %s }" %
                LilyPond.from_NoteContainer(NoteContainer("C"), value.dots(8)),
                "pdftest first test",
            ))
        self.assertTrue(
            LilyPond.to_pdf(LilyPond.from_Bar(self.tbar), "pdftest2"))
        self.assertTrue(
            LilyPond.to_pdf(LilyPond.from_Bar(self.mbar), "pdftest3"))

    def test_to_png(self):
        self.assertTrue(
            LilyPond.to_png(
                "{ %s }" %
                LilyPond.from_NoteContainer(NoteContainer("C"), value.dots(8)),
                "pn1",
            ))
        self.assertTrue(LilyPond.to_png(LilyPond.from_Bar(self.tbar), "pn2"))
        self.assertTrue(LilyPond.to_png(LilyPond.from_Bar(self.mbar), "pn3"))
Пример #10
0
class test_LilyPond(unittest.TestCase):

    def setUp(self):
        self.commonbar = Bar()
        self.ebar = Bar('E', (4, 4))
        self.fbar = Bar('F', (6, 8))
        self.tbar = Bar('C', (4, 4))
        self.mbar = Bar('C', (4, 4))
        for y in [self.commonbar, self.ebar, self.fbar]:
            map(lambda x: y + x, ['C', 'E', 'G', 'B'])
        map(lambda x: self.tbar.place_notes(NoteContainer(x), 6), [
            'C',
            'E',
            'G',
            'B',
            'C',
            'E',
            ])
        map(lambda x: self.mbar.place_notes(NoteContainer(x), 4), ['C', 'E'])
        map(lambda x: self.mbar.place_notes(NoteContainer(x), 6), ['G', 'B', 'C'
            ])
        self.track1 = Track()
        self.track1 + self.commonbar
        self.track2 = Track()
        self.track2 + self.commonbar
        self.track2 + self.ebar
        self.composition1 = Composition()
        self.composition1.add_track(self.track1)
        self.composition2 = Composition()
        self.composition2.add_track(self.track1)
        self.composition2.add_track(self.track2)

    def test_from_Note(self):
        self.assertEqual(LilyPond.from_Note(Note('C'), standalone=False), "c'")
        self.assertEqual(LilyPond.from_Note(Note('C#'), standalone=False),
                         "cis'")
        self.assertEqual(LilyPond.from_Note(Note('C##'), standalone=False),
                         "cisis'")
        self.assertEqual(LilyPond.from_Note(Note('Cb'), standalone=False),
                         "ces'")
        self.assertEqual(LilyPond.from_Note(Note('Cbb'), standalone=False),
                         "ceses'")
        self.assertEqual(LilyPond.from_Note(Note('C', 0), standalone=False),
                         'c,,,')
        self.assertEqual(LilyPond.from_Note(Note('C', 1), standalone=False),
                         'c,,')
        self.assertEqual(LilyPond.from_Note(Note('C', 2), standalone=False),
                         'c,')
        self.assertEqual(LilyPond.from_Note(Note('C', 3), standalone=False), 'c'
                         )
        self.assertEqual(LilyPond.from_Note(Note('C', 4), standalone=False),
                         "c'")
        self.assertEqual(LilyPond.from_Note(Note('C', 5), standalone=False),
                         "c''")
        self.assertEqual(LilyPond.from_Note(Note('C', 6), standalone=False),
                         "c'''")
        self.assertEqual(LilyPond.from_Note(Note('C', 7), standalone=False),
                         "c''''")

    def test_from_NoteContainer(self):
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'),
                         standalone=False), "c'")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 4,
                         standalone=False), "c'4")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer(['C', 'E']),
                         standalone=False), "<c' e'>")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer(['C', 'E']),
                         4, standalone=False), "<c' e'>4")

        # issue #37

        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 16,
                         standalone=False), "c'16")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 16.0,
                         standalone=False), "c'16")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'),
                         value.dots(16), standalone=False), "c'16.")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 0.25,
                         standalone=False), "c'\\longa")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'), 0.5,
                         standalone=False), "c'\\breve")

    def test_from_Bar(self):
        self.assertEqual(LilyPond.from_Bar(self.commonbar),
                         "{ \\time 4/4 \\key c \\major c'4 e'4 g'4 b'4 }")
        self.assertEqual(LilyPond.from_Bar(self.ebar),
                         "{ \\time 4/4 \\key e \\major c'4 e'4 g'4 b'4 }")
        self.assertEqual(LilyPond.from_Bar(self.fbar),
                         "{ \\time 6/8 \\key f \\major c'8 e'8 g'8 b'8 }")

    def test_from_Track(self):
        self.assertEqual(LilyPond.from_Track(self.track1),
                         "{ { c'4 e'4 g'4 b'4 } }")
        self.assertEqual(LilyPond.from_Track(self.track2),
                         "{ { c'4 e'4 g'4 b'4 } { \\key e \\major c'4 e'4 g'4 b'4 } }"
                         )

    def test_from_Composition(self):
        self.assertEqual(LilyPond.from_Composition(self.composition1),
                         '\\header { title = "Untitled" composer = "" opus = "" } { { c\'4 e\'4 g\'4 b\'4 } }'
                         )
        self.assertEqual(LilyPond.from_Composition(self.composition2),
                         '\\header { title = "Untitled" composer = "" opus = "" } { { c\'4 e\'4 g\'4 b\'4 } } { { c\'4 e\'4 g\'4 b\'4 } { \\key e \\major c\'4 e\'4 g\'4 b\'4 } }'
                         )

    def test_from_Suite(self):
        LilyPond.from_Suite(None)

    def test_dotted_notes(self):
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'),
                         value.dots(8), standalone=False), "c'8.")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer('C'),
                         value.dots(4, 2), standalone=False), "c'4..")

    def test_to_pdf(self):
        self.assert_(LilyPond.to_pdf('{ %s }'
                      % LilyPond.from_NoteContainer(NoteContainer('C'),
                     value.dots(8)), 'pdftest first test'))
        self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.tbar), 'pdftest2'))
        self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.mbar), 'pdftest3'))

    def test_to_png(self):
        self.assert_(LilyPond.to_png('{ %s }'
                      % LilyPond.from_NoteContainer(NoteContainer('C'),
                     value.dots(8)), 'pn1'))
        self.assert_(LilyPond.to_png(LilyPond.from_Bar(self.tbar), 'pn2'))
        self.assert_(LilyPond.to_png(LilyPond.from_Bar(self.mbar), 'pn3'))
Пример #11
0
class test_LilyPond(unittest.TestCase):
    def setUp(self):
        self.commonbar = Bar()
        self.ebar = Bar("E", (4, 4))
        self.fbar = Bar("F", (6, 8))
        self.tbar = Bar("C", (4, 4))
        self.mbar = Bar("C", (4, 4))
        self.a_minor_bar = Bar("a", (4, 4))
        self.b_flat_minor_bar = Bar("bb", (4, 4))
        self.f_sharp_minor_bar = Bar("f#", (4, 4))
        for y in [self.commonbar, self.ebar, self.fbar]:
            map(lambda x: y + x, ["C", "E", "G", "B"])
        map(lambda x: self.tbar.place_notes(NoteContainer(x), 6), ["C", "E", "G", "B", "C", "E"])
        map(lambda x: self.mbar.place_notes(NoteContainer(x), 4), ["C", "E"])
        map(lambda x: self.mbar.place_notes(NoteContainer(x), 6), ["G", "B", "C"])
        self.track1 = Track()
        self.track1 + self.commonbar
        self.track2 = Track()
        self.track2 + self.commonbar
        self.track2 + self.ebar
        self.composition1 = Composition()
        self.composition1.add_track(self.track1)
        self.composition2 = Composition()
        self.composition2.add_track(self.track1)
        self.composition2.add_track(self.track2)

    def test_from_Note(self):
        self.assertEqual(LilyPond.from_Note(Note("C"), standalone=False), "c'")
        self.assertEqual(LilyPond.from_Note(Note("C#"), standalone=False), "cis'")
        self.assertEqual(LilyPond.from_Note(Note("C##"), standalone=False), "cisis'")
        self.assertEqual(LilyPond.from_Note(Note("Cb"), standalone=False), "ces'")
        self.assertEqual(LilyPond.from_Note(Note("Cbb"), standalone=False), "ceses'")
        self.assertEqual(LilyPond.from_Note(Note("C", 0), standalone=False), "c,,,")
        self.assertEqual(LilyPond.from_Note(Note("C", 1), standalone=False), "c,,")
        self.assertEqual(LilyPond.from_Note(Note("C", 2), standalone=False), "c,")
        self.assertEqual(LilyPond.from_Note(Note("C", 3), standalone=False), "c")
        self.assertEqual(LilyPond.from_Note(Note("C", 4), standalone=False), "c'")
        self.assertEqual(LilyPond.from_Note(Note("C", 5), standalone=False), "c''")
        self.assertEqual(LilyPond.from_Note(Note("C", 6), standalone=False), "c'''")
        self.assertEqual(LilyPond.from_Note(Note("C", 7), standalone=False), "c''''")

    def test_from_NoteContainer(self):
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer("C"), standalone=False), "c'")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer("C"), 4, standalone=False), "c'4")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer(["C", "E"]), standalone=False), "<c' e'>")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer(["C", "E"]), 4, standalone=False), "<c' e'>4")

        # issue #37

        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer("C"), 16, standalone=False), "c'16")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer("C"), 16.0, standalone=False), "c'16")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer("C"), value.dots(16), standalone=False), "c'16.")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer("C"), 0.25, standalone=False), "c'\\longa")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer("C"), 0.5, standalone=False), "c'\\breve")

    def test_from_Bar(self):
        self.assertEqual(LilyPond.from_Bar(self.commonbar), "{ \\time 4/4 \\key c \\major c'4 e'4 g'4 b'4 }")
        self.assertEqual(LilyPond.from_Bar(self.ebar), "{ \\time 4/4 \\key e \\major c'4 e'4 g'4 b'4 }")
        self.assertEqual(LilyPond.from_Bar(self.fbar), "{ \\time 6/8 \\key f \\major c'8 e'8 g'8 b'8 }")
        self.assertEqual(LilyPond.from_Bar(self.a_minor_bar), "{ \\time 4/4 \\key a \\minor }")
        self.assertEqual(LilyPond.from_Bar(self.b_flat_minor_bar), "{ \\time 4/4 \\key bes \\minor }")
        self.assertEqual(LilyPond.from_Bar(self.f_sharp_minor_bar), "{ \\time 4/4 \\key fis \\minor }")

    def test_from_Track(self):
        self.assertEqual(LilyPond.from_Track(self.track1), "{ { c'4 e'4 g'4 b'4 } }")
        self.assertEqual(
            LilyPond.from_Track(self.track2), "{ { c'4 e'4 g'4 b'4 } { \\key e \\major c'4 e'4 g'4 b'4 } }"
        )

    def test_from_Composition(self):
        self.assertEqual(
            LilyPond.from_Composition(self.composition1),
            '\\header { title = "Untitled" composer = "" opus = "" } { { c\'4 e\'4 g\'4 b\'4 } }',
        )
        self.assertEqual(
            LilyPond.from_Composition(self.composition2),
            "\\header { title = \"Untitled\" composer = \"\" opus = \"\" } { { c'4 e'4 g'4 b'4 } } { { c'4 e'4 g'4 b'4 } { \\key e \\major c'4 e'4 g'4 b'4 } }",
        )

    def test_from_Suite(self):
        LilyPond.from_Suite(None)

    def test_dotted_notes(self):
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer("C"), value.dots(8), standalone=False), "c'8.")
        self.assertEqual(LilyPond.from_NoteContainer(NoteContainer("C"), value.dots(4, 2), standalone=False), "c'4..")

    def test_to_pdf(self):
        self.assert_(
            LilyPond.to_pdf(
                "{ %s }" % LilyPond.from_NoteContainer(NoteContainer("C"), value.dots(8)), "pdftest first test"
            )
        )
        self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.tbar), "pdftest2"))
        self.assert_(LilyPond.to_pdf(LilyPond.from_Bar(self.mbar), "pdftest3"))

    def test_to_png(self):
        self.assert_(LilyPond.to_png("{ %s }" % LilyPond.from_NoteContainer(NoteContainer("C"), value.dots(8)), "pn1"))
        self.assert_(LilyPond.to_png(LilyPond.from_Bar(self.tbar), "pn2"))
        self.assert_(LilyPond.to_png(LilyPond.from_Bar(self.mbar), "pn3"))
Пример #12
0
def from_Track(track):
    c = Composition()
    c.add_track(track)
    return _composition2musicxml(c).toprettyxml()
Пример #13
0
def from_Bar(bar):
    c = Composition()
    t = Track()
    t.add_bar(bar)
    c.add_track(t)
    return _composition2musicxml(c).toprettyxml()