-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexture_sleepy.py
123 lines (111 loc) · 4.74 KB
/
texture_sleepy.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import math
import sys
import chordDec
import mido
import sampler
import numpy
class sleepy(chordDec.chordDec):
def process_callback(self) -> None:
index = 0
while True:
index += 1
yield from self.waitTime(0)
print("seg", self.playListSize())
self.setIns(1, 0) # 设置一号通道为钢琴
pianoShift = self.shiftPlayList(24)
self.setIns(2, 24) # 设置二号通道为吉他
guitarShift = self.shiftPlayList(40)
self.setIns(3, 95) # 设置三号通道为弦乐
print("pianoShift", pianoShift)
self.playIndexRV(1, 4, 3, -12)
self.playIndexRV(2, 4, 3, -12)
self.playIndexRV(3, 4, 3, -12)
if self.playListSize() == 1:
# 一个音:
self.playIndexRV(1, 4, 2, 0) # [1,0,4,Guitar,p4]
self.playIndexRV(1, 3, 1, pianoShift) # [1,0,4,Piano,p4]
elif self.playListSize() == 2:
# 两个音:
# [1,0,4,Guitar,p4],[2,0,4,Guitar,p4]
# [1,0,4,Piano,p4],[2,0,4,Piano,p4]
self.playIndexRV(1, 3, 1, pianoShift)
self.playIndexRV(1, 4, 2, guitarShift)
yield from self.waitTime(32)
self.playIndexRV(2, 3, 1, pianoShift)
self.playIndexRV(2, 4, 2, guitarShift)
elif self.playListSize() == 3:
# 三个音:
# [1,0,4,Guitar,p4],[2,0,4,Guitar,p4,+12],[3,0,4,Guitar,p4]
# [1,0,4,Piano,p4],[2,2,2,Piano,p3,+12],[3,0,4,Piano,p4]
self.playIndexRV(1, 3, 1, pianoShift)
self.playIndexRV(3, 3, 1, pianoShift)
self.playIndexRV(1, 4, 2, guitarShift)
self.playIndexRV(2, 4, 2, guitarShift + 12)
self.playIndexRV(3, 4, 2, guitarShift)
yield from self.waitTime(32)
self.playIndexRV(2, 3, 1, pianoShift + 12)
elif self.playListSize() == 4:
# 四个音:
# [1,0,4,Guitar,p4],[2,0,4,Guitar,p4,+12],[3,0,4,Guitar,p4,+12],[4,0,4,Guitar,p4]
# [1,0,4,Piano,p4],[2,2,2,Piano,p3,+12],[3,2,2,Piano,p3,+12],[4,0,4,Piano,p4]
self.playIndexRV(1, 4, 2, guitarShift)
self.playIndexRV(2, 4, 2, guitarShift + 12)
self.playIndexRV(3, 4, 2, guitarShift + 12)
self.playIndexRV(4, 4, 2, guitarShift)
self.playIndexRV(1, 3, 1, pianoShift)
self.playIndexRV(4, 3, 1, pianoShift)
yield from self.waitTime(32)
self.playIndexRV(2, 3, 1, pianoShift + 12)
self.playIndexRV(3, 3, 1, pianoShift + 12)
elif self.playListSize() == 5:
# 五个音:
# [1,0,4,Guitar,p4],[2,0,4,Guitar,p4,+12],[3,0,4,Guitar,p4,+12],[4,0,4,Guitar,p4],[5,0,4,Guitar,p4]
# [1,0,4,Piano,p4],[2,2,2,Piano,p3,+12],[3,0,4,Piano,p3,+12],[4,0,4,Piano,p4],[5,0,4,Piano,p4]
self.playIndexRV(1, 4, 2, guitarShift)
self.playIndexRV(2, 4, 2, guitarShift + 12)
self.playIndexRV(4, 4, 2, guitarShift)
self.playIndexRV(5, 4, 2, guitarShift)
yield from self.waitTime(32)
self.playIndexRV(2, 3, 1, pianoShift + 12)
self.playIndexRV(3, 4, 2, guitarShift + 12)
if __name__ == "__main__":
print("texture:sleepy")
midi_in = sys.argv[1] # "test.mid"
midi_out = sys.argv[2] # 'out.mid'
track_melody = 0
track_chord = 1
try:
track_melody = int(sys.argv[3])
track_chord = int(sys.argv[4])
print("track_melody:", track_melody)
print("track_chord:", track_chord)
except Exception:
pass
track_mix = track_melody
try:
track_mix = int(sys.argv[5])
print("track_mix:", track_mix)
except Exception:
pass
player = sleepy()
gen = player.process()
melody_full, chord_full, tonal = sampler.sampleMidi(midi_in,
track_melody=track_melody,
track_chord=track_chord)
player.setTonal(tonal)
mid_src = mido.MidiFile(midi_in)
melody_full = numpy.array(melody_full).reshape(-1, 4)
for i in range(len(chord_full)):
melody = melody_full[i]
chord = chord_full[i]
for note in melody:
player.pushMelody(note)
player.setChord(chord)
for i in range(16):
next(gen)
player.stopAll()
# print(player.ins)
# print(player.tracks)
mf = player.linkEvents(mid_src.ticks_per_beat)
mf.tracks[0] = mid_src.tracks[track_mix]
mf.save(midi_out)