Example #1
0
    def test_degree_in_key(self):
        """
        Ensure that it plays in G major.
        """
        from sebastian.core.transforms import degree_in_key
        from sebastian.core.notes import Key, major_scale
        h1 = self.make_horizontal_sequence()
        keyed = h1 | degree_in_key(Key("G", major_scale))

        self.assertEqual(keyed._elements, [
            {
                'degree': 1,
                'pitch': -1
            },
            {
                'degree': 2,
                'pitch': 1
            },
            {
                'degree': 3,
                'pitch': 3
            },
            {
                'degree': 1,
                'pitch': -1
            },
        ])
Example #2
0
    def test_degree_in_key(self):
        """
        Ensure that it plays in G major.
        """
        from sebastian.core.transforms import degree_in_key
        from sebastian.core.notes import Key, major_scale
        h1 = self.make_horizontal_sequence()
        keyed = h1 | degree_in_key(Key("G", major_scale))

        self.assertEqual(keyed._elements, [
            {'degree': 1, 'pitch': -1},
            {'degree': 2, 'pitch': 1},
            {'degree': 3, 'pitch': 3},
            {'degree': 1, 'pitch': -1},
        ])
Example #3
0
    def test_play_notes_in_midi_pitches(self):
        """
        Ensure that it plays in G major.
        """
        from sebastian.core.transforms import degree_in_key, midi_pitch, add
        from sebastian.core.notes import Key, major_scale
        from sebastian.core import MIDI_PITCH, DURATION_64
        h1 = self.make_horizontal_sequence()
        keyed = h1 | degree_in_key(Key("G", major_scale))
        positioned = keyed | add({'octave': 4, DURATION_64: 8})
        pitched = positioned | midi_pitch()

        self.assertEqual(pitched._elements, [
            {'degree': 1, 'pitch': -1, DURATION_64: 8, MIDI_PITCH: 55, 'octave': 4},
            {'degree': 2, 'pitch': 1, DURATION_64: 8, MIDI_PITCH: 57, 'octave': 4},
            {'degree': 3, 'pitch': 3, DURATION_64: 8, MIDI_PITCH: 59, 'octave': 4},
            {'degree': 1, 'pitch': -1, DURATION_64: 8, MIDI_PITCH: 55, 'octave': 4},
        ])
Example #4
0
    def test_play_notes_in_midi_pitches(self):
        """
        Ensure that it plays in G major.
        """
        from sebastian.core.transforms import degree_in_key, midi_pitch, add
        from sebastian.core.notes import Key, major_scale
        from sebastian.core import MIDI_PITCH, DURATION_64
        h1 = self.make_horizontal_sequence()
        keyed = h1 | degree_in_key(Key("G", major_scale))
        positioned = keyed | add({'octave': 4, DURATION_64: 8})
        pitched = positioned | midi_pitch()

        self.assertEqual(pitched._elements, [
            {
                'degree': 1,
                'pitch': -1,
                DURATION_64: 8,
                MIDI_PITCH: 55,
                'octave': 4
            },
            {
                'degree': 2,
                'pitch': 1,
                DURATION_64: 8,
                MIDI_PITCH: 57,
                'octave': 4
            },
            {
                'degree': 3,
                'pitch': 3,
                DURATION_64: 8,
                MIDI_PITCH: 59,
                'octave': 4
            },
            {
                'degree': 1,
                'pitch': -1,
                DURATION_64: 8,
                MIDI_PITCH: 55,
                'octave': 4
            },
        ])
Example #5
0
"""
The main title theme to HBO's Game of Thrones by Ramin Djawadi
"""

from sebastian.core import Point, HSeq, OSequence
from sebastian.core.transforms import midi_pitch, degree_in_key, add
from sebastian.core.notes import Key, major_scale, minor_scale
from sebastian.midi import write_midi

C_Major = Key("C", major_scale)
C_minor = Key("C", minor_scale)

motive_degrees = HSeq(Point(degree=n) for n in [5, 1, 3, 4])

motive_rhythm_1 = HSeq(Point(duration_64=n) for n in [16, 16, 8, 8])
motive_rhythm_2 = HSeq(Point(duration_64=n) for n in [48, 48, 8, 8, 32, 32, 8, 8])

motive_1 = motive_degrees & motive_rhythm_1
motive_2 = (motive_degrees * 2) & motive_rhythm_2

# add key and octave
seq1 = (motive_1 * 4) | add({"octave": 5}) | degree_in_key(C_minor)
seq2 = (motive_1 * 4) | add({"octave": 5}) | degree_in_key(C_Major)
seq3 = motive_2 | add({"octave": 4}) | degree_in_key(C_minor)

seq = (seq1 + seq2 + seq3) | midi_pitch() | OSequence

write_midi.write("game_of_thrones.mid", [seq], instruments=[49], tempo=350000)
Example #6
0
# merge
seq5 = seq3 // seq4

# 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()
Example #7
0
# merge
seq5 = seq3 // seq4

# 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
Example #8
0
"""
The main title theme to HBO's Game of Thrones by Ramin Djawadi
"""

from sebastian.core import Point, HSeq, OSequence
from sebastian.core.transforms import midi_pitch, degree_in_key, add
from sebastian.core.notes import Key, major_scale, minor_scale
from sebastian.midi import write_midi

C_Major = Key("C", major_scale)
C_minor = Key("C", minor_scale)

motive_degrees = HSeq(Point(degree=n) for n in [5, 1, 3, 4])

motive_rhythm_1 = HSeq(Point(duration_64=n) for n in [16, 16, 8, 8])
motive_rhythm_2 = HSeq(
    Point(duration_64=n) for n in [48, 48, 8, 8, 32, 32, 8, 8])

motive_1 = motive_degrees & motive_rhythm_1
motive_2 = (motive_degrees * 2) & motive_rhythm_2

# add key and octave
seq1 = (motive_1 * 4) | add({"octave": 5}) | degree_in_key(C_minor)
seq2 = (motive_1 * 4) | add({"octave": 5}) | degree_in_key(C_Major)
seq3 = motive_2 | add({"octave": 4}) | degree_in_key(C_minor)

seq = (seq1 + seq2 + seq3) | midi_pitch() | OSequence

write_midi.write("game_of_thrones.mid", [seq], instruments=[49], tempo=350000)
Example #9
0
# add

s5 = s4 | add({"octave": 4, DURATION_64: 8})

assert list(s5) == [
    {'degree': 1, DURATION_64: 8, 'octave': 4},
    {'degree': 2, DURATION_64: 8, 'octave': 4},
    {'degree': 3, DURATION_64: 8, 'octave': 4},
    {'degree': 2, DURATION_64: 8, 'octave': 4},
    {'degree': 1, DURATION_64: 8, 'octave': 4}
]

# degree_in_key

s6 = s5 | degree_in_key(Key("C", major_scale))

assert list(s6) == [
    {'degree': 1, DURATION_64: 8, 'octave': 4, 'pitch': -2},
    {'degree': 2, DURATION_64: 8, 'octave': 4, 'pitch': 0},
    {'degree': 3, DURATION_64: 8, 'octave': 4, 'pitch': 2},
    {'degree': 2, DURATION_64: 8, 'octave': 4, 'pitch': 0},
    {'degree': 1, DURATION_64: 8, 'octave': 4, 'pitch': -2}
]

# midi_pitch

s7 = s6 | midi_pitch()

assert list(s7) == [
    {'degree': 1, MIDI_PITCH: 48, DURATION_64: 8, 'octave': 4, 'pitch': -2},
Example #10
0

def write(filename, seq):
    with open(filename, "w") as f:
        f.write("{ ")
        for point in seq:
            f.write(point["lilypond"])
            f.write(" ")
        f.write("}\n")


if __name__ == "__main__":
    from sebastian.core import DURATION_64
    from sebastian.core import HSeq, Point
    from sebastian.core.notes import Key, major_scale
    from sebastian.core.transforms import degree_in_key, add, lilypond

    seq = HSeq(Point(degree=n) for n in [1, 2, 3, 4])
    seq = seq | add({DURATION_64: 16, "octave": 5})

    C_major = Key("C", major_scale)

    seq = seq | degree_in_key(C_major) | lilypond()

    write("test.ly", seq)