示例#1
0
def build_movement():
    # Define our alberti bass signature.
    alberti = arpeggio([0, 2, 1, 2])

    # Create the basic interval pattern.
    intervals = HSeq({DEGREE: x} for x in [1, 5, 1, 4, 1, 5, 1])

    # Create the rhythm
    rhythm = HSeq({DURATION_64: x} for x in [128, 64, 64, 64, 64, 64, 64])

    # Set specific chords to be used in certain measures.
    intervals[1]["chord"] = (-3, -1, 0, 2)  # second inversion 7th
    intervals[3]["chord"] = (-3, 0, 2)      # second inversion
    intervals[5]["chord"] = (-5, -3, 0)     # first inversion

    # Combine the sequences, make them chords, produce alberti on the chords,
    # fill with each being 8, expand it to a flat sequence.
    melody = intervals & rhythm | chord() | alberti | fill(8) | expand

    # Define our key
    C_major = Key("C", major_scale)

    #key(major_scale(-2))

    # Set the degree, add the midi pitch, make it an OSequence, add debugging information.
    return melody | degree_in_key_with_octave(C_major, 5) | midi_pitch() | OSequence | debug
示例#2
0
def build_movement():
    # Define our alberti bass signature.
    alberti = arpeggio([0, 2, 1, 2])

    # Create the basic interval pattern.
    intervals = HSeq({DEGREE: x} for x in [1, 5, 1, 4, 1, 5, 1])

    # Create the rhythm
    rhythm = HSeq({DURATION_64: x} for x in [128, 64, 64, 64, 64, 64, 64])

    # Set specific chords to be used in certain measures.
    intervals[1]["chord"] = (-3, -1, 0, 2)  # second inversion 7th
    intervals[3]["chord"] = (-3, 0, 2)      # second inversion
    intervals[5]["chord"] = (-5, -3, 0)     # first inversion

    # Combine the sequences, make them chords, produce alberti on the chords, 
    # fill with each being 8, expand it to a flat sequence.
    melody = intervals & rhythm | chord() | alberti | fill(8) | expand

    # Define our key
    C_major = Key("C", major_scale)

    #key(major_scale(-2))

    # Set the degree, add the midi pitch, make it an OSequence, add debugging information.
    return melody | degree_in_key_with_octave(C_major, 5) | midi_pitch() | OSequence | debug
示例#3
0
        def next(self):
                keys = EvenKeyboard().notes
                self.keys = list(keys)
                keycount = len(self.keys)
                right = HSeq(self.keys.__getslice__(keycount-(keycount/2), keycount-(keycount/4)))
                whole = 64
                seed_pitch = random.randint(1,12)
                seed_unit = random.choice([1,2,4,8,16])
                seed_duration = whole/seed_unit
                measure_length = 4*whole
                phrase_lengths = range(50,90)
                phrase_length = Randomized(phrase_lengths)
                reaches = range(-1,1)
                reach = Wandering(reaches)

                finger1 = Finger(
                length = 16,
                note = Wandering(right),
                duration = Randomized([2,4,4,4,4,4,4,4,4,4,5,6,9,8,8,8,8,16,32,32,32]),
                velocity = Randomized(range(20,127)),
                rest = Randomized([2,4,8,16,32,32,32,32,32,32,32,32])
                )

                finger2 = Finger(
                        length = 160,
                        note = Wandering(keys),
                        duration = Randomized(range(2,80)),
                        velocity = Wandering(range(50,90)),
                        rest = Randomized([1,2,3,4,5])
                        )

                finger3 = Finger(
                length = 16,
                note = Wandering(keys),
                duration = Randomized([2,4,8,16,32]),
                velocity = Randomized(range(20,127)),
                rest = Oscilating([2,4,8,16,32])
                )


                beat = metrenome(seed_unit,seed_pitch,5,seed_duration)
                measure_length = beat.next_offset()
                phrase_length_new = phrase_length.next()
                phrase1 = finger1.next(phrase_length_new)
                phrase1_b = mutate(phrase1,1,2,1,0,0)
                phrase2 = finger2.next(phrase_length_new*2)
                phrase2_b = mutate(phrase2,1,2,1,0,0)
                phrase3 = finger1.next(phrase_length_new*3)
                phrase1_3 = mutate(phrase3,1,2,1,0,0)
                #metrenome 
                left_seq = (phrase1*3)+phrase1_b+(phrase3*3)+phrase1_b
                right_seq = (phrase2*3)+phrase2_b+(phrase2*3)+phrase2_b
                left_composition = (left_seq*2)+((left_seq*2) | transpose(reach.next()) )+(left_seq*2)
                self.output = left_composition#//(right_seq | delay(phrase1.next_offset()*2))
                self.hand = [finger1,finger2]
                self.last = self.output | transforms.stretch(.25)
                try:
                        player.play([self.last | midi_pitch()])
                except Exception as e:
                        print e
示例#4
0
        def next(self):
                keys = MajorKeyboard().notes
                self.keys = list(keys)
                keys = HSeq(self.keys.__getslice__(40,80))


                keycount = len(self.keys)

                stretch_length = (80)

                finger1 = Finger(
                length = 16,
                note = Wandering(keys),
                duration = Wandering([2,4,8]),
                velocity = Wandering(range(50,100)),
                rest = Randomized([2,4])
                )
                x=200
                
                drone = (finger1.next(90) | transforms.stretch(1))*2
                #drone = multiply(drone,[-3])
                measure = drone.next_offset()-1
                #metrenome 
                alpha = finger1.next(200)
                self.hand = [finger1]
                self.last = alpha


                try:
                        player.play([self.last | midi_pitch()])
                except Exception as e:
                        print e
示例#5
0
    def test_lilypond_transform(self):
        """
        Ensure that it plays in G major.
        """
        from sebastian.core.transforms import midi_pitch, add, lilypond
        from sebastian.core import DURATION_64
        from sebastian.core import HSeq, Point
        h1 = HSeq([Point(pitch=pitch) for pitch in [0, 1, 2, 3, 4, 11, -4, -11]])
        positioned = h1 | add({'octave': 4, DURATION_64: 8})
        pitched = positioned | midi_pitch()
        pitched[3]['octave'] = 5
        pitched[4]['octave'] = 3
        lilyed = pitched | lilypond()

        import pprint
        pprint.pprint(list(lilyed))

        self.assertEqual(lilyed._elements, [
            {'duration_64': 8,
                'lilypond': 'd8',
                'midi_pitch': 50,
                'octave': 4,
                'pitch': 0},
            {'duration_64': 8,
                'lilypond': 'a8',
                'midi_pitch': 57,
                'octave': 4,
                'pitch': 1},
            {'duration_64': 8,
                'lilypond': 'e8',
                'midi_pitch': 52,
                'octave': 4,
                'pitch': 2},
            {'duration_64': 8,
                'lilypond': "b'8",
                'midi_pitch': 59,
                'octave': 5,
                'pitch': 3},
            {'duration_64': 8,
                'lilypond': 'fis,8',
                'midi_pitch': 54,
                'octave': 3,
                'pitch': 4},
            {'duration_64': 8,
                'lilypond': 'fisis8',
                'midi_pitch': 55,
                'octave': 4,
                'pitch': 11},
            {'duration_64': 8,
                'lilypond': 'bes8',
                'midi_pitch': 58,
                'octave': 4,
                'pitch': -4},
            {'duration_64': 8,
                'lilypond': 'beses8',
                'midi_pitch': 57,
                'octave': 4,
                'pitch': -11}
        ])
示例#6
0
 def get_octaves(self, octaves):
     output = OSequence()
     for r in octaves:
         #octave = OSequence(Point(pitch=pitch, octave=r, velocity=90) for pitch in self.pitches)
         octave = []
         for pitch in self.pitches:
             new_point = Point(pitch=pitch, octave=r, velocity=90, duration_64=10)
             print OSequence(new_point) | midi_pitch()
             octave.append(new_point)
         output = output + OSequence(octave)
     return output
示例#7
0
        def next(self):
                keys = MajorKeyboard().notes
                self.keys = list(keys)

                keycount = len(self.keys)

                stretch_length = ()

                finger1 = Finger(
                length = 300,
                note = Wandering(HSeq(self.keys.__getslice__(20,80))),
                duration = Wandering([8,4]),
                velocity = Wandering(range(50,51)),
                rest = Randomized([8])
                )
                
                finger2 = Finger(
                length = 300,
                note = Oscilating(HSeq(self.keys.__getslice__(10,20))),
                duration = Oscilating([32]),
                velocity = Oscilating(range(50,51)),
                rest = Randomized([0])
                )

                finger3 = Finger(
                length = 300,
                note = Wandering(self.keys),
                duration = Wandering([2,4,6,8,16]),
                velocity = Wandering(range(50,80)),
                rest = Wandering([2,4,6,8,16])
                )

                g = 50
                self.hand = [finger1]
                sequence_1 = (finger1.next(g)//finger2.next(g))
                sequence_1_a = sequence_1 | transpose(11)
                sequence_1_b = sequence_1 | transpose(1) 

                sequence_2 = (finger2.next(g)//finger2.next(g))
                sequence_2_a = sequence_1 | transpose(11)
                sequence_2_b = sequence_1 | transpose(1) 

                sequence_3 = (finger1.next(g)//finger1.next(g))
                sequence_3_a = sequence_1 | transpose(11)
                sequence_3_b = sequence_1 | transpose(1) 

                solo = finger3.next(g*6)
                self.last = sequence_1+sequence_1_a+((sequence_2_b+sequence_2+sequence_1+sequence_3_a+sequence_3_b+sequence_1_a))+sequence_2

                try:
                        player.play([sequence_1 | midi_pitch()])
                except Exception as e:
                        print e
示例#8
0
        def next(self):
                keys = PentatonicKeyboard().notes
                self.keys = list(keys)
                keycount = len(self.keys)
                stretch_length = random.randint(2,5)
                left_low = random.randint(keycount/4,(keycount/2))
                left_range = random.randint(1,8)
                mids = HSeq(self.keys.__getslice__(left_low,left_low+left_range))
                right = HSeq(self.keys.__getslice__(keycount-(keycount/4), keycount-1))

                finger1 = Finger(
                length = 16,
                note = Wandering(mids),
                duration = Oscilating([2,4,8,16,32]),
                velocity = Randomized(range(20,127)),
                rest = Randomized([2,4,8,16,32])
                )

                finger2 = Finger(
                        length = 160,
                        note = Wandering(right),
                        duration = Randomized(range(2,80)),
                        velocity = Wandering(range(50,90)),
                        rest = Randomized([1,2,3,4,5])
                        )

                finger3 = Finger(
                length = 16,
                note = Wandering(mids),
                duration = Randomized([2,4,8,16,32]),
                velocity = Randomized(range(20,127)),
                rest = Oscilating([2,4,8,16,32])
                )


                x=800
                
                drone = (finger1.next(256) | transforms.stretch(.5))*2
                #drone = multiply(drone,[-3])
                measure = drone.next_offset()
                #metrenome 
                alpha = (drone*2)+(mutate(drone,1,2,1,2,0))+(drone*2)+(mutate(drone,1,2,1,0,1))+(drone*2)+(mutate(drone,1,2,1,0,1))+(drone*2)
                drone2 = (finger3.next(256) | transforms.stretch(1))*2
                mutated_drone2 = (mutate(drone2,1,2,1,0,1))
                beta = (drone*2)+(mutated_drone2)+(drone2*2)+(mutated_drone2)+(drone2*2)+(mutated_drone2)+(drone2*2)
                solo1 = finger2.next(measure)+(mutate(finger2.next(measure),octave=1) | delay(measure))+(finger2.next(measure) | delay(measure))
                output = alpha//(beta | delay(measure*2))
                self.hand = [finger1,finger2]
                self.last = output | transforms.stretch(1)
                try:
                        player.play([self.last | midi_pitch()])
                except Exception as e:
                        print e
示例#9
0
        def next(self, mutation_matrix=[0,0,0,0,0]):
                measure = metrenome(120,octave=5, bpm=120)
                voice1 = measure |mutate(1,2,0,0,0)
                half_measure = metrenome(120,octave=5, bpm=240)
                delay = metrenome(10,octave=5, bpm=120)
                new = half_measure | delay(delay.next_offset())

                self.last = measure // voice1

                try:
                        player.play([self.last | midi_pitch()])
                except Exception as e:
                        print e
示例#10
0
        def next(self):
                keys = PentatonicKeyboard().notes
                self.keys = list(keys)
                keycount = len(self.keys)
                stretch_length = random.randint(2,5)
                left_low = random.randint(keycount/4,(keycount/2))
                left_range = random.randint(1,8)
                mids = self.keys.__getslice__(left_low,left_low+left_range)
                right = HSeq(self.keys.__getslice__(keycount-(keycount/4), keycount-1))
                print mids

                finger1 = Finger(
                length = 16,
                note = Wandering(mids),
                duration = Oscilating([2,4,8,16,32]),
                velocity = Randomized(range(20,127)),
                rest = Randomized([2,4,8,16,32])
                )

                finger2 = Finger(
                        length = 160,
                        note = Wandering(right),
                        duration = Randomized(range(2,80)),
                        velocity = Wandering(range(50,90)),
                        rest = Randomized([5])
                        )

                finger1_shifted = Finger(
                length = 16,
                note = Wandering(keys),
                duration = Oscilating([10]),
                velocity = Randomized(range(20,127)),
                rest = Randomized([1])
                )


                x=800
                
                drone = (finger1.next(856*2) | transforms.stretch(.5))*2
                self.drone = drone
                self.phrase1 = (drone*2)+(mutate(drone,1,2,1,2,1))+(drone*2)+(mutate(drone,1,2,1,0,1))+(drone*2)+(mutate(drone,1,2,1,0,1))+(drone*2)
                measure = drone.next_offset()-1
                #metrenome 
                #alpha = generations(phrase1,5,1,2,1,2,0)
                output = self.phrase1
                self.hand = [finger1,finger2]
                self.last = output | transforms.stretch(.5) 
                try:
                        player.play([self.last | midi_pitch()])
                except Exception as e:
                        print e
示例#11
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},
        ])
示例#12
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
            },
        ])
示例#13
0
def build_movement():
    C_major = Key("C", major_scale)
    intervals = sequence_map("degree", [1, 5, 1, 4, 1, 5, 1])
    intervals[1]["inversion"] = (-3, -1, 0, 2)  # second inversion 7th
    intervals[3]["inversion"] = (-3, 0, 2)  # second inversion
    intervals[5]["inversion"] = (-5, -3, 0)  # first inversion
    rhythm = sequence_map(DURATION_64, [128, 64, 64, 64, 64, 64, 64])
    melody = intervals & rhythm
    melody = melody.map_points(chord())
    duration = 8
    for point in melody:
        point["sequence"] = alberti(point["sequence"], duration) * (point[DURATION_64] / (8 * duration))
    melody = expand_sequences(melody)

    # note values filled-out for C major in octave 5 then MIDI pitches calculated
    melody = melody | degree_in_key_with_octave(C_major, 5) | midi_pitch()

    melody = OSequence(melody)
    index(melody._elements)

    return melody
示例#14
0
        def next(self):
                keys = MinorBluesKeyboard().notes
                self.keys = list(keys)

                keycount = len(self.keys)

                stretch_length = ()

                finger1 = Finger(
                length = 300,
                note = Wandering(HSeq(self.keys.__getslice__(20,40))),
                duration = Wandering([8]),
                velocity = Wandering(range(50,51)),
                rest = Randomized([8])
                )
                
                finger2 = Finger(
                length = 300,
                note = Oscilating(HSeq(self.keys.__getslice__(10,20))),
                duration = Oscilating([32]),
                velocity = Oscilating(range(50,51)),
                rest = Randomized([0])
                )

                alpha = finger1.next(60)
                beta = finger2.next(60)
                gamma = finger1.next(70)
                self.hand = [finger1]
                sequence_1 = (alpha//beta) | transforms.stretch(.5)
                #sequence_2 = sequence_1 | transforms.stretch(.5)
                sequence_2 = sequence_1 | transpose(11)
                sequence_3 = sequence_1 | transpose(1)
                self.last = sequence_1+sequence_2+sequence_3+sequence_1

                try:
                        player.play([self.last | midi_pitch()])
                except Exception as e:
                        print e
示例#15
0
        def next(self):
                keys = MajorKeyboard().notes
                self.keys = list(keys)
                keys = HSeq(self.keys.__getslice__(40,50))

                keycount = len(self.keys)

                stretch_length = ()

                finger1 = Finger(
                length = 160,
                note = Wandering(keys),
                duration = Wandering([2]),
                velocity = Wandering(range(50,51)),
                rest = Randomized([2])
                )
                
                finger2 = Finger(
                length = 160,
                note = Wandering(keys),
                duration = Wandering([2]),
                velocity = Wandering(range(50,51)),
                rest = Randomized([2])
                )

                alpha = finger1.next(100) 
                beta = finger2.next(100)
                gamma = finger1.next(70)
                self.hand = [finger1]
                self.last = alpha // beta


                try:
                        player.play([self.last | midi_pitch()])
                except Exception as e:
                        print e
示例#16
0
from sebastian.core.transforms import midi_pitch, degree_in_key_with_octave, add
from sebastian.core.notes import Key, major_scale

from sebastian.midi import write_midi


def alberti(triad):
    """
    takes a VSeq of 3 notes and returns an HSeq of those notes in an
    alberti figuration.
    """
    return HSeq(triad[i] for i in [0, 2, 1, 2])


# an abstract VSeq of 3 notes in root position (degree 1, 3 and 5)
root_triad = VSeq(Point(degree=n) for n in [1, 3, 5])


quaver_point = Point({DURATION_64: 8})

# an OSequence with alberti figuration repeated 16 times using quavers
alberti_osequence = OSequence(alberti(root_triad) * 16 | add(quaver_point))

C_major = Key("C", major_scale)

# note values filled-out for C major in octave 5 then MIDI pitches calculated
seq = alberti_osequence | degree_in_key_with_octave(C_major, 5) | midi_pitch()

# write to file:
write_midi.write("alberti.mid", [seq])
示例#17
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)
示例#18
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)
示例#19
0
down_degrees = [6, 4, 3, 2, 1, 2, 3, 4]
final_degree = [1]

sections = [
    (up_degrees, 4, range(14)),
    (down_degrees, 4, range(13, -2, -1)),
    (final_degree, 32, range(1)),
]

hanon_1 = OSequence()

for section in sections:
    pattern, duration_64, offset = section
    for o in offset:
        for note in pattern:
            hanon_1.append({"degree": note + o, DURATION_64: duration_64})

hanon_1 = hanon_1 | degree_in_key_with_octave(Key("C", major_scale), 4) | midi_pitch()

hanon_rh_1 = hanon_1
hanon_lh_1 = hanon_1 | transpose(-12)

seq = hanon_lh_1 // hanon_rh_1


if __name__ == "__main__":
    f = open("hanon.mid", "w")
    s = SMF([seq])
    s.write(f)
    f.close()
示例#20
0
 def play(self):
     player.play([OSequence(self.notes | midi_pitch())])
示例#21
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
示例#22
0
        def next(self):
                keys = MinorKeyboard().notes
                self.keys = list(keys)
                keycount = len(self.keys)
                base = Randomized([40,80,120,240]).next()
                measure = metrenome(base/2,octave=5, bpm=base)
                #two sequences that make different audible metrenomes
                tick = metrenome(base/2,octave=10, bpm=base)
                tock = metrenome(base/2,octave=10, bpm=base, velocity=Randomized([0,20,40,60,80,90]).next()) | mutate(0,0,30,0,0)


                finger1 = Finger(
                length = measure.next_offset(),
                note = Wandering(HSeq(self.keys.__getslice__(20,23))),
                duration = Wandering([4,8,16,32,64]),
                velocity = Wandering(range(50,51)),
                rest = Randomized([8])
                )

                finger2 = Finger(
                length = measure.next_offset(),
                note = Wandering(HSeq(self.keys.__getslice__(23,24))),
                duration = Wandering([4,8,16,32,64]),
                velocity = Wandering(range(30,41)),
                rest = Randomized([8])
                )

                finger3 = Finger(
                length = measure.next_offset(),
                note = Wandering(HSeq(self.keys.__getslice__(26,27))),
                duration = Wandering([4,8,16,32,64]),
                velocity = Wandering(range(30,41)),
                rest = Randomized([8])
                )

                transpositions = Randomized([-2,2,4,6,8])

                def fade_mutate(incoming, count, mutation_matrix=[0,2,30,0,0]):
                        output = OSequence()
                        last = incoming
                        for r in xrange(16):
                                current = last | mutate(mutation_matrix[0], mutation_matrix[1], mutation_matrix[2], mutation_matrix[3], mutation_matrix[4])
                                output += (tock//incoming // current) | transpose(transpositions.next())
                                last = current
                        return output

                def generate_jazz():
                        seq_1 = fade_mutate(finger1.next(measure.next_offset()),4)
                        seq_2 = fade_mutate(finger1.next(measure.next_offset()),4)
                        output = seq_1 // seq_2
                        return output

                output = generate_jazz()//(generate_jazz() | delay(measure.next_offset()*1))//(generate_jazz() | delay(measure.next_offset()*2))
                

                self.hand = [finger1]
                sequence_1 = (output)

                self.last = sequence_1
                #print self.last | midi_pitch()
                try:
                        player.play([self.last | midi_pitch()])
                except Exception as e:
                        print e
示例#23
0
    {'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},
    {'degree': 2, MIDI_PITCH: 50, DURATION_64: 8, 'octave': 4, 'pitch': 0},
    {'degree': 3, MIDI_PITCH: 52, DURATION_64: 8, 'octave': 4, 'pitch': 2},
    {'degree': 2, MIDI_PITCH: 50, DURATION_64: 8, 'octave': 4, 'pitch': 0},
    {'degree': 1, MIDI_PITCH: 48, DURATION_64: 8, 'octave': 4, 'pitch': -2}
]
示例#24
0
    def test_lilypond_transform(self):
        """
        Ensure that it plays in G major.
        """
        from sebastian.core.transforms import midi_pitch, add, lilypond
        from sebastian.core import DURATION_64
        from sebastian.core import HSeq, Point
        h1 = HSeq(
            [Point(pitch=pitch) for pitch in [0, 1, 2, 3, 4, 11, -4, -11]])
        positioned = h1 | add({'octave': 4, DURATION_64: 8})
        pitched = positioned | midi_pitch()
        pitched[3]['octave'] = 5
        pitched[4]['octave'] = 3
        lilyed = pitched | lilypond()

        import pprint
        pprint.pprint(list(lilyed))

        self.assertEqual(lilyed._elements, [{
            'duration_64': 8,
            'lilypond': 'd8',
            'midi_pitch': 50,
            'octave': 4,
            'pitch': 0
        }, {
            'duration_64': 8,
            'lilypond': 'a8',
            'midi_pitch': 57,
            'octave': 4,
            'pitch': 1
        }, {
            'duration_64': 8,
            'lilypond': 'e8',
            'midi_pitch': 52,
            'octave': 4,
            'pitch': 2
        }, {
            'duration_64': 8,
            'lilypond': "b'8",
            'midi_pitch': 59,
            'octave': 5,
            'pitch': 3
        }, {
            'duration_64': 8,
            'lilypond': 'fis,8',
            'midi_pitch': 54,
            'octave': 3,
            'pitch': 4
        }, {
            'duration_64': 8,
            'lilypond': 'fisis8',
            'midi_pitch': 55,
            'octave': 4,
            'pitch': 11
        }, {
            'duration_64': 8,
            'lilypond': 'bes8',
            'midi_pitch': 58,
            'octave': 4,
            'pitch': -4
        }, {
            'duration_64': 8,
            'lilypond': 'beses8',
            'midi_pitch': 57,
            'octave': 4,
            'pitch': -11
        }])
示例#25
0
def end(scale):
    return HSeq(scale[i] for i in [2, 1]) | add(quaver_point)


def h2(scale):
    return HSeq(scale[i] for i in [0, 4, 3, 4]) | add(quaver_point)


def h2_end1(scale):
    return HSeq(scale[i] for i in [0, 4]) | add(quaver_point)


# there's two important quarter notes used at the ends of sections
e1 = HSeq(scale[3]) | add(quarter_point)
e2 = HSeq(scale[0]) | add(quarter_point)

partA = h1(scale) + h1_end1(scale) + e1 + h1(scale) + end(scale) + e2
partB = h2(scale) + h2_end1(scale) + e1 + h2(scale) + end(scale) + e2

# here we see the basic structure of the song
oseq = OSequence((partA * 2) + (partB * 2))

C_major = Key("C", major_scale)

# note values filled-out for C major in octave 5 then MIDI pitches calculated
seq = oseq | degree_in_key_with_octave(C_major, 5) | midi_pitch()

# write to file:
write_midi.write("shortning_bread_1.mid", [seq])
示例#26
0
from sebastian.core import VSeq, HSeq, Point, OSequence
from sebastian.core.transforms import midi_pitch, degree_in_key_with_octave, add
from sebastian.core.notes import Key, major_scale

from sebastian.midi import write_midi


def alberti(triad):
    """
    takes a VSeq of 3 notes and returns an HSeq of those notes in an
    alberti figuration.
    """
    return HSeq(triad[i] for i in [0, 2, 1, 2])


# an abstract VSeq of 3 notes in root position (degree 1, 3 and 5)
root_triad = VSeq(Point(degree=n) for n in [1, 3, 5])

quaver_point = Point({DURATION_64: 8})

# an OSequence with alberti figuration repeated 16 times using quavers
alberti_osequence = OSequence(alberti(root_triad) * 16 | add(quaver_point))

C_major = Key("C", major_scale)

# note values filled-out for C major in octave 5 then MIDI pitches calculated
seq = alberti_osequence | degree_in_key_with_octave(C_major, 5) | midi_pitch()

# write to file:
write_midi.write("alberti.mid", [seq])
示例#27
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)
示例#28
0
down_degrees = [6, 4, 3, 2, 1, 2, 3, 4]
final_degree = [1]

sections = [
    (up_degrees, 4, range(14)),
    (down_degrees, 4, range(13, -2, -1)),
    (final_degree, 32, range(1)),
]

hanon_1 = OSequence()

for section in sections:
    pattern, duration_64, offset = section
    for o in offset:
        for note in pattern:
            hanon_1.append({"degree": note + o, DURATION_64: duration_64})

hanon_1 = hanon_1 | degree_in_key_with_octave(Key("C", major_scale),
                                              4) | midi_pitch()

hanon_rh_1 = hanon_1
hanon_lh_1 = hanon_1 | transpose(-12)

seq = hanon_lh_1 // hanon_rh_1

if __name__ == "__main__":
    f = open("hanon.mid", "w")
    s = SMF([seq])
    s.write(f)
    f.close()
示例#29
0
        def next(self):
                keys = Keyboard().notes
                self.keys = keys
                stretch_length = random.randint(2,5)
                left_low = random.randint(40,70)
                left_range = random.randint(1,2)
                left = HSeq(list(keys).__getslice__(left_low,left_low+left_range))
                right = HSeq(list(keys).__getslice__(20,50))

                note1 = Wandering(keys)
                duration1 = Oscilating(range(2,8))
                velocity1 = Randomized(range(20,127))

                note2 = Wandering(left)
                duration2 = Randomized(range(0,len(left)))
                velocity2 = Wandering(range(70,90))

                note3 = note2.echo()
                duration3 = Randomized(range(2,12))
                velocity3 = Wandering(range(20,127))

                finger1 = Finger(
                length = 16,
                note = note1,
                duration = duration1,
                velocity = velocity1
                )

                finger2 = Finger(
                        length = 160,
                        note = note2,
                        duration = duration2,
                        velocity = velocity2
                        )

                finger3 = Finger(
                        length = 16,
                        note = note2,
                        duration = duration3,
                        velocity = velocity3
                        )

                finger4 = Finger(
                        length = 16,
                        note = Wandering([1,2,3]),
                        duration = Randomized([4,6]),
                        velocity = Wandering(range(40,50))
                        )
                x=800
                
                drone = (finger1.next(50) | transforms.stretch(1))*3
                solo1 = finger1.next(x)
                #solo2 = mutate(finger1.last,1,1,1,1)
                solo2 = finger1.next(x)
                output = drone+(solo1//solo2//(drone*10)//finger3.next(x) | transforms.stretch(5))+(drone*3)
                self.hand = [finger1,finger2,finger3,finger4]
                self.last = output
                try:
                        player.play([output | midi_pitch()])
                except Exception as e:
                        print e