Exemple #1
0
    def add_arpeggio(self,
                     track,
                     time,
                     chords_beat=[],
                     notes_beat=[],
                     chords=[],
                     velocities=[],
                     note_skip=LoopingArray([1, 2, 3]),
                     length=0):

        track = MidiTrack(channel=track, tempo=self.tempo)

        beat_index = time
        bi = beat_index
        while beat_index - time < length:
            chordindex = 0
            beat_value, _ = chords_beat.next()
            chord = chords.next()
            while (bi < beat_index + beat_value) and (bi < length):
                chordindex = note_skip.next()
                note = chord[chordindex % len(chord)]
                notes_beat_value, notes_duration_value = notes_beat.next()
                track.add_note(bi, notes_duration_value, note,
                               velocities.next())

                bi += notes_beat_value
            beat_index += beat_value

        self.midi.tracks.append(track)
    def testLoopingArray(self):
        l = LoopingArray([1, 2, 3, 4, 5])
        
        assert l.next() == 1
        assert l.next() == 2
        assert l.next() == 3
        assert l.next() == 4
        assert l.next() == 5
        assert l.next() == 1
        
        l = LoopingArray([1, 2, 3, 4, 5], [('add', StaticIterator(value=2))])
        
        assert l.next() == 1
        assert l.next() == 3
        assert l.next() == 5
        assert l.next() == 2
        
        l = LoopingArray([1, 2, 3, 4, 5], [('add', StaticIterator(value=2)), ('dec', StaticIterator(value=1))])
        
        assert l.next() == 1
        assert l.next() == 2
        assert l.next() == 3
        assert l.next() == 4
        assert l.next() == 5
        assert l.next() == 1

        l = LoopingArray([1, 2, 3, 4, 5], [('add', StaticIterator(value=1)), ('dec', StaticIterator(value=2))])
        
        assert l.next() == 1
        assert l.next() == 5
        assert l.next() == 4
        assert l.next() == 3
        assert l.next() == 2
        assert l.next() == 1
        assert l.next() == 5
Exemple #3
0
import sys
sys.path.append("../")

from midiutil.TrackGen import LoopingArray

if __name__ == '__main__':
    arr = LoopingArray(
                       [x for x in range(128)],
                       functioniterator=[
                                         ('add', LoopingArray([1, 2, 3], functioniterator=[
                                                                                         ('add', LoopingArray([1, 2, 3], functioniterator=[
                                                                                                                                           ('add', LoopingArray([1,2,3], id='      array4', debug=True))
                                                                                                                                           ],
                                                                                                              id='    array3', debug=True)
                                                                                          )
                                                                                         ],
                                                              id='  array2', debug=True)
                                          )
                                         ],
                       id='array1', debug=True
                       )
    
    for _ in range(20):
        arr.next()
Exemple #4
0
    def testLoopingArray(self):
        l = LoopingArray([1, 2, 3, 4, 5])

        assert l.next() == 1
        assert l.next() == 2
        assert l.next() == 3
        assert l.next() == 4
        assert l.next() == 5
        assert l.next() == 1

        l = LoopingArray([1, 2, 3, 4, 5], [('add', StaticIterator(value=2))])

        assert l.next() == 1
        assert l.next() == 3
        assert l.next() == 5
        assert l.next() == 2

        l = LoopingArray([1, 2, 3, 4, 5], [('add', StaticIterator(value=2)),
                                           ('dec', StaticIterator(value=1))])

        assert l.next() == 1
        assert l.next() == 2
        assert l.next() == 3
        assert l.next() == 4
        assert l.next() == 5
        assert l.next() == 1

        l = LoopingArray([1, 2, 3, 4, 5], [('add', StaticIterator(value=1)),
                                           ('dec', StaticIterator(value=2))])

        assert l.next() == 1
        assert l.next() == 5
        assert l.next() == 4
        assert l.next() == 3
        assert l.next() == 2
        assert l.next() == 1
        assert l.next() == 5
Exemple #5
0
def PatternGenerator(seed, n, reduce_function, max):
	pattern = seed
	for _ in range(n):
		pattern.append(reduce(reduce_function, pattern) % max)
	return pattern[1:]

def GetLoopingArray(base, arr):
	print arr
	return LoopingArray([[scale[(base + x) % len(scale)]] for x in arr])
	

tracks = {
          'Notes 1': {
                         'notearrays': [
                                        {
                                         'beat': LoopingArray([(2,2)]),
                                         'notearray': GetLoopingArray(base, PatternGenerator([1], 10, lambda x, y: x+y, 11)),
                                         'velocities': LoopingArray([100,90,95,70])
                                        }
                                        ],
                         },
          'Notes 2': {
                       'notearrays': [
                                      {
                                       'beat': LoopingArray([(4, 4),(4, 4),(4, 4),(4, 4),(4, 4),(4, 4),(1, 1),(1, 1),(0.5, 0.5),(0.5, 0.5)]),
                                       'notearray': GetLoopingArray(base+20, PatternGenerator([1], 20, lambda x, y: x+(y+2), 13)),
                                       'velocities': LoopingArray([70,100,90,95])
                                      },
                                        ],
                         },
          'Notes 3': {
Exemple #6
0
def GetLoopingArray(base, arr):
	print arr
	return LoopingArray([[scale[(base + x) % len(scale)]] for x in arr])
Exemple #7
0
import sys
sys.path.append("../")

from midiutil.MidiGenerator import MidiGenerator
from midiutil.Scales import MINOR, buildScale
from midiutil.TrackGen import LoopingIncrementalIndexedArray, LoopingArray

midiGenerator = MidiGenerator(tempo=105)

sc = MINOR

mscale = buildScale(sc, 48, 80)
notes = LoopingArray([
                      [mscale[x] for x in [0, 2, 4, 6]], # chord 1
                      [mscale[x] for x in [3, 5, 7, 9]], # chord 2 
                      [mscale[x] for x in [5, 7, 11]] # chord 3
                      ], functioniterator=[('add', LoopingArray([1, 1, 2]))])
chord_beats = LoopingArray([(4, 4), (2, 2)])
notes_beats = LoopingArray([(0.25, 0.25)])
velocities = LoopingArray([120, 120])
note_skip = LoopingArray([0, 1, 2, 3, 1], functioniterator=[('add', LoopingArray([1, 2]))])

midiGenerator.add_arpeggio(0, 0, chords_beat=chord_beats, notes_beat=notes_beats, chords=notes, velocities=velocities, note_skip=note_skip, length=32)

notes = LoopingIncrementalIndexedArray([[x] for x in buildScale(sc, 36, 48)], [1, 1, 2, -1, 2])
beats = LoopingArray([(4, 4)])
velocities = LoopingArray([110, 110])
midiGenerator.add_track (1, 0, beat=beats, notes=notes, velocities=velocities, length=32)

midiGenerator.write()
from midiutil.TrackGen import LoopingArray
from midiutil.MidiGenerator import MidiGenerator

midiGenerator = MidiGenerator(tempo=120)

scale = reduce(lambda x, y: x + y,
               [[y + (12 * x) for y in [0, 2, 3, 5, 7, 8, 10]]
                for x in range(10)])

base = 20

tracks = {
    'Bass track': {
        'notearrays': [{
            'beat':
            LoopingArray([(16, 16)]),
            'notearray':
            LoopingArray([[scale[base + x]] for x in [0, 1, 2, 3, 4, 5, 6]],
                         functioniterator=[('add', LoopingArray([4]))]),
            'velocities':
            LoopingArray([100])
        }],
    },
}

i = 0
for track in tracks:
    print 'processing %s' % track

    notearrays = tracks[track]['notearrays']
    for n in notearrays:
Exemple #9
0
midiGenerator = MidiGenerator(tempo=120)

scale = reduce(lambda x, y: x + y,
               [[y + (12 * x) + 24 for y in [0, 2, 0, 7, 0, 7, 0, 8]]
                for x in range(5)])

pos = 0
for base in [10, 5, 7, 3]:
    #base = 10

    tracks = {
        'running notes': {
            'notearrays': [
                {
                    'beat':
                    LoopingArray([(1, 1), (0.5, 0.5), (0.25, 0.25),
                                  (1.5, 1.5)]),
                    'notearray':
                    LoopingArray([[scale[(base + (x * 2)) % len(scale)]]
                                  for x in range(5)]),
                    'velocities':
                    LoopingArray([100, 90, 110, 70, 80])
                },
                {
                    'beat':
                    LoopingArray([(0.5, 0.5), (0.25, 0.25), (2.0, 2.0)]),
                    'notearray':
                    LoopingArray([[scale[(base + (x * 3)) % len(scale)]]
                                  for x in range(9)]),
                    'velocities':
                    LoopingArray([90, 91, 49, 110, 93, 49, 69])
                },
Exemple #10
0
sys.path.append("../")

from midiutil.TrackGen import LoopingArray
from midiutil.MidiGenerator import MidiGenerator

midiGenerator = MidiGenerator(tempo=120)

scale = reduce(lambda x, y:x + y, [[36 + y + (12 * (x)) for y in [0, 2, 4, 7, 11]] for x in range (3)])

base = 20

tracks = {
          'Bass track': {
                         'notearrays': [
                                        {
                                         'beat': LoopingArray([(16, 16)]),
                                         'notearray': LoopingArray([[scale[(base + x) % len(scale)]] for x in [0, 1, 3, 2]]),
                                         'velocities': LoopingArray([100])
                                        }
                                        ],
                         },
          'Chords 1': {
                       'notearrays': [
                                      {
                                       'beat': LoopingArray([(8, 8), (16, 16)]),
                                       'notearray': LoopingArray([[scale[(base + x) % len(scale)]] for x in [10, 12, 14, 16]]),
                                       'velocities': LoopingArray([100])
                                      },
                                      {
                                       'beat': LoopingArray([(8, 8), (16, 16)]),
                                       'notearray': LoopingArray([[scale[(base + x) % len(scale)]] for x in [20, 22, 21]]),
from midiutil.MidiGenerator import MidiGenerator

midiGenerator = MidiGenerator(tempo=128)

scale = reduce(lambda x, y: x + y,
               [[y + (12 * x) + 36 for y in [0, 2, 3, 5, 7, 8, 10]]
                for x in range(5)])

base = 0
pos = 0
tracks = {
    'running notes': {
        'notearrays': [
            {
                'beat':
                LoopingArray([(1.5, 1.5), (1.5, 1.5), (1.5, 1.5), (1.5, 1.5),
                              (1, 1), (1, 1)]),
                'notearray':
                LoopingArray([[scale[(base + (x * 2)) % len(scale)]]
                              for x in [0, 5, 2, 6, 4, 8]]),
                'velocities':
                LoopingArray([100, 90, 110, 70, 80])
            },
        ],
    }
}

i = 0
for track in tracks:
    print 'processing %s' % track

    notearrays = tracks[track]['notearrays']
Exemple #12
0
l = 3
pos = 0
for mod in range(4):
    for notepattern in [
        [0, 2, 7, 8],
        [2, 5, 7, 10],
        [0, 3, 7, 8],
        [3, 5, 7, 8, 10],
    ]:
        scale = reduce(lambda x, y: x + y,
                       [[y + (12 * x) + 48 for y in notepattern]
                        for x in range(3)])
        midiGenerator.add_track(
            0,
            pos,
            beat=LoopingArray([(0.5, 1.0)]),
            notes=LoopingArray([[x] for x in scale],
                               functioniterator=[
                                   ('add', StaticIterator(value=1)),
                                   ('mult', LoopingArray([1, 2, 1 + mod]))
                               ],
                               id='notes'),
            velocities=LoopingArray([100, 90, 110, 70, 80]),
            length=l)
        pos += l

    for notepattern in [
        [5, 2, 7, 8],
        [7, 5, 7, 10],
        [8, 3, 7, 8],
        [11, 5, 7, 3],
Exemple #13
0
from midiutil.TrackGen import LoopingArray

if __name__ == '__main__':
    arr = LoopingArray([x for x in range(128)],
                       functioniterator=[
                           ('add',
                            LoopingArray([1, 2, 3],
                                         functioniterator=[
                                             ('add',
                                              LoopingArray(
                                                  [1, 2, 3],
                                                  functioniterator=[
                                                      ('add',
                                                       LoopingArray(
                                                           [1, 2, 3],
                                                           id='      array4',
                                                           debug=True))
                                                  ],
                                                  id='    array3',
                                                  debug=True))
                                         ],
                                         id='  array2',
                                         debug=True))
                       ],
                       id='array1',
                       debug=True)

    for _ in range(20):
        arr.next()
Exemple #14
0
from midiutil.MidiGenerator import MidiGenerator
from midiutil.Scales import *

midiGenerator = MidiGenerator()

sc = HARMONIC_MINOR_SCALE
scale = [[x] for x in buildScale(sc, 48, 80)]

l = 3
pos = 0
for k in range(2):
    for i in range(16):
        midiGenerator.add_track(
            0,
            pos,
            beat=LoopingArray([(0.5, 1.0), (0.5, 1.0), (1.0, 2.0),
                               (0.5, 0.5)]),
            notes=LoopingArray(
                scale,
                functioniterator=[
                    ('add', StaticIterator(value=1)),
                    ('mult', LoopingArray([5 + (i), 3 + (i * 2), 2 + (i * 3)]))
                ],
                id='notes'),
            velocities=LoopingArray([100, 90, 110, 70, 80]),
            length=l)
        pos += l

    for j in range(8):
        for i in range(1):
            midiGenerator.add_track(
                0,
midiGenerator = MidiGenerator(tempo=90)

scale = reduce(lambda x, y: x + y,
               [[y + (12 * x) + 36 for y in [0, 7, 14, 8, 10, 7, 8]]
                for x in range(2)])

pos = 0
for base in [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]:
    #base = 10

    tracks = {
        'running notes': {
            'notearrays': [{
                'beat':
                LoopingArray([(1, 1), (0.5, 0.5), (0.25, 0.25), (1.5, 1.5)]),
                'notearray':
                LoopingArray([[scale[(base + (x * 2)) % len(scale)]]
                              for x in range(5)]),
                'velocities':
                LoopingArray([100, 90, 110, 70, 80])
            }, {
                'beat':
                LoopingArray([(0.5, 0.5), (0.25, 0.25), (2.0, 2.0)]),
                'notearray':
                LoopingArray([[scale[(base + (x * 3)) % len(scale)]]
                              for x in range(9)]),
                'velocities':
                LoopingArray([90, 91, 49, 110, 93, 49, 69])
            }, {
                'beat':
import sys
sys.path.append("../")

from midiutil.TrackGen import LoopingArray
from midiutil.MidiGenerator import MidiGenerator

midiGenerator = MidiGenerator(tempo=120)

x = LoopingArray([5,1,6])
note = 0
scale = []
for _ in range(10):
    scale += [36+note]
    note += x.next()

tracks = {
          'Bass track': {
                         'notearrays': [
                                        {
                                         'beat': LoopingArray([(0.25,1.0)]),
                                         'notearray': LoopingArray([[x] for x in scale],
                                                                   functioniterator=[
                                                                                     ('add',LoopingArray([1,2,3,4,5])),
                                                                                     ('dec',LoopingArray([0,0,1,2])),
                                                                                     ]),
                                         'velocities': LoopingArray([x for x in range(100,110)],
                                                                    functioniterator=[
                                                                                      ('add',LoopingArray([1,2,4,1,3])),
                                                                                     ('dec',LoopingArray([0,7,3,2])),
                                                                                      ])
                                        }
Exemple #17
0
from midiutil.TrackGen import LoopingArray
from midiutil.MidiGenerator import MidiGenerator

midiGenerator = MidiGenerator(tempo=120)

scale = reduce(lambda x, y: x + y,
               [[y + (12 * x) for y in [0, 3, 5, 7, 8, 10]]
                for x in range(10)])

base = 20

tracks = {
    'Bass track': {
        'notearrays': [{
            'beat':
            LoopingArray([(8, 8)]),
            'notearray':
            LoopingArray([[scale[base + x]] for x in [0, 1, 3, 2]]),
            'velocities':
            LoopingArray([100])
        }],
    },
    'Chords 1': {
        'notearrays': [{
            'beat':
            LoopingArray([(8, 8), (16, 16)]),
            'notearray':
            LoopingArray([[scale[base + x]] for x in [10, 12, 14, 16]]),
            'velocities':
            LoopingArray([100])
        }, {