-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (46 loc) · 1.57 KB
/
Copy pathmain.py
File metadata and controls
51 lines (46 loc) · 1.57 KB
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
import fake_piano
class FakePianoConsole():
def __init__(self):
self.options = {
1 : 'Play midi file',
2 : 'Exit'
}
self.functions = {
1: self.fake_play,
2: exit
}
def showMenu(self):
for option, desc in self.options.items():
print(str(option)+'.', desc)
def run(self):
while True:
self.showMenu()
print('Option:', end=' ')
selected = int(input())
if(0 < selected <= len(self.options)):
self.functions[selected]()
break
while True:
pass
def fake_play(self):
player = fake_piano.FixedSpeedPlayer(playback_speed=1)
reader = fake_piano.Reader(read_threshold=0.02)
print('Midi file name:', end=' ')
reader.load_midi('midi/'+input()+'.mid')
print('----- Midi tracks -----')
print(*reader.available_midi_tracks(), sep='\n')
print('-----------------------')
print('Midi melody track:', end=' ')
reader.load_melody(input())
print('Midi accomp track:', end=' ')
reader.load_accomp(input())
player.set_playable(reader.create_playable())
player.set_input(fake_piano.input_tools.KeyboardInput())
player.set_output(fake_piano.output_tools.FluidSynthOutput('./sf2/steinway.sf2'))
player.start()
print('\n+ Playing... Press CTRL+C to stop')
if __name__=='__main__':
try:
FakePianoConsole().run()
except KeyboardInterrupt:
print('\nInterrupted')