-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.py
48 lines (35 loc) · 1.25 KB
/
filter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from ds import *
from ds.instruments import AcousticGuitar, Piano, Saxophone
class FilteredPlayer(Player):
def __init__(self, original, predicate):
Player.__init__(self, original.connection)
self.original = original
self.predicate = predicate
def play(self, note):
if self.predicate(note):
return self.original.play(note)
return 0
def loop(self, note, period):
if self.predicate(note):
return self.original.loop(note, period)
return 0
isEvenNote = lambda n: n.offset % 16 == 0
isOddNote = lambda n: not isEvenNote(n)
def filterNote(player, func, predicate, *args, **kwargs):
return FilteredPlayer(player, predicate).call(func, *args, **kwargs)
root = AcousticGuitar(60, 0.5, 127, 0)
third = Piano(64, 0.5, 127, 0)
fifth = Saxophone(67, 0.5, 127, 0)
beat = Note(60, 127, 0.5, 127, 0)
def playEvens():
return player.call(filterNote, Player.majorScale, isEvenNote, root)
def playOdds():
return player.call(filterNote, Player.majorScale, isOddNote, root)
def playThird():
return player.majorScale(third)
def playFifth():
return player.majorScale(fifth)
def playBeat():
return player.majorScale(beat)
if __name__ == '__main__':
player = connect()