예제 #1
0
 def test_write(self):
     import tempfile
     pitches = HSeq({"pitch": n} for n in [-2, 0, 2, -3])
     seq = pitches | add({"octave": 5, DURATION_64: 16}) | lilypond()
     f = tempfile.NamedTemporaryFile(suffix=".ly", delete=False)
     write(f.name, seq)
     with open(f.name) as g:
         self.assertEqual(g.read(), "{ c'4 d'4 e'4 f'4 }")
예제 #2
0
 def test_write(self):
     import tempfile
     pitches = HSeq({"pitch": n} for n in [-2, 0, 2, -3])
     seq = pitches | add({"octave": 5, DURATION_64: 16}) | lilypond()
     f = tempfile.NamedTemporaryFile(suffix=".ly", delete=False)
     write(f.name, seq)
     with open(f.name) as g:
         self.assertEqual(g.read(), "{ c'4 d'4 e'4 f'4 }")
예제 #3
0
from sebastian.lilypond import write_lilypond

# construct sequences using lilypond syntax
melody = parse("e4 e f g g f e d c c d e")
A = parse("e4. d8 d2")
Aprime = parse("d4. c8 c2")

two_bars = melody + A + melody + Aprime
two_bars = two_bars | midi_to_pitch()
two_bars = two_bars | add({"octave": 5})

velocities = [
    "pppppp", "ppppp", "pppp", "ppp", "pp", "p", "mp", "mf", "f", "ff", "fff",
    "ffff"
]

for d in velocities:
    two_bars_with_dynamics = two_bars | dynamics(d)
    write_midi.write("ode_%s.mid" % (d, ), [two_bars_with_dynamics])

two_bars_ff_lily = two_bars | dynamics("ff") | lilypond()
write_lilypond.write("ode_ff.ly", two_bars_ff_lily)

crescendo = two_bars | dynamics("ppp", "ff")
write_midi.write("ode_crescendo.mid", [crescendo])
write_lilypond.write("ode_crescendo.ly", crescendo | lilypond())

diminuendo = two_bars | dynamics("mf", "pppp")
write_midi.write("ode_diminuendo.mid", [diminuendo])
write_lilypond.write("ode_diminuendo.ly", diminuendo | lilypond())
예제 #4
0
from sebastian.lilypond.interp import parse
from sebastian.core.transforms import dynamics, lilypond, midi_to_pitch, add
from sebastian.midi import write_midi
from sebastian.lilypond import write_lilypond

# construct sequences using lilypond syntax
melody = parse("e4 e f g g f e d c c d e")
A = parse("e4. d8 d2")
Aprime = parse("d4. c8 c2")

two_bars = melody + A + melody + Aprime
two_bars = two_bars | midi_to_pitch()
two_bars = two_bars | add({"octave": 5})

velocities = ["pppppp", "ppppp", "pppp", "ppp", "pp", "p", "mp", "mf", "f", "ff", "fff", "ffff"]

for d in velocities:
    two_bars_with_dynamics = two_bars | dynamics(d)
    write_midi.write("ode_%s.mid" % (d,), [two_bars_with_dynamics])

two_bars_ff_lily = two_bars | dynamics("ff") | lilypond()
write_lilypond.write("ode_ff.ly", two_bars_ff_lily)

crescendo = two_bars | dynamics("ppp", "ff")
write_midi.write("ode_crescendo.mid", [crescendo])
write_lilypond.write("ode_crescendo.ly", crescendo | lilypond())

diminuendo = two_bars | dynamics("mf", "pppp")
write_midi.write("ode_diminuendo.mid", [diminuendo])
write_lilypond.write("ode_diminuendo.ly", diminuendo | lilypond())
예제 #5
0
# play MIDI
player.play([seq5])

# write to MIDI
write_midi.write("seq5.mid", [seq5])

# contruct a horizontal sequence of scale degrees
seq6 = HSeq(Point(degree=degree) for degree in [1, 2, 3, 2, 1])

# put that sequence into C major, octave 4 quavers
C_MAJOR = Key("C", major_scale)
seq7 = seq6 | add({"octave": 4, DURATION_64: 8}) | degree_in_key(C_MAJOR)

# convert to MIDI pitch and play
player.play([OSequence(seq7 | midi_pitch())])

# sequence of first four degree of a scale
seq8 = HSeq(Point(degree=n) for n in [1, 2, 3, 4])

# add duration and octave
seq8 = seq8 | add({DURATION_64: 16, "octave": 5})

# put into C major
seq8 = seq8 | degree_in_key(C_MAJOR)

# annotate with lilypond
seq8 = seq8 | lilypond()

# write out lilypond file
write("example.ly", seq8)
예제 #6
0
player.play([seq5])

# write to MIDI
write_midi.write("seq5.mid", [seq5])

# contruct a horizontal sequence of scale degrees
seq6 = HSeq(Point(degree=degree) for degree in [1, 2, 3, 2, 1])

# put that sequence into C major, octave 4 quavers
C_MAJOR = Key("C", major_scale)
seq7 = seq6 | add({"octave": 4, DURATION_64: 8}) | degree_in_key(C_MAJOR)

# convert to MIDI pitch and play
player.play([OSequence(seq7 | midi_pitch())])


# sequence of first four degree of a scale
seq8 = HSeq(Point(degree=n) for n in [1, 2, 3, 4])

# add duration and octave
seq8 = seq8 | add({DURATION_64: 16, "octave": 5})

# put into C major
seq8 = seq8 | degree_in_key(C_MAJOR)

# annotate with lilypond
seq8 = seq8 | lilypond()

# write out lilypond file
write("example.ly", seq8)