-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
32 lines (24 loc) · 1.42 KB
/
test.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
'''Test converts a midi file using the dictionaries generated by process.py.'''
import argparse
import midi
import process
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Test convert a midi file using the dictionaries generated by process.py.')
parser.add_argument('input', help='path to input midi file.')
parser.add_argument('output', help='path to output midi file (converted).')
args = parser.parse_args()
source_filename = args.input
output_filename = args.output
pitch_dict = process.load_dictionary(process.checkpoint_path + '/pitch_dict.txt')
pitch_rev_dict = process.get_reverse_dictionary(pitch_dict)
step_dict = process.load_dictionary(process.checkpoint_path + '/step_dict.txt')
step_rev_dict = process.get_reverse_dictionary(step_dict)
dur_dict = process.load_dictionary(process.checkpoint_path + '/dur_dict.txt')
dur_rev_dict = process.get_reverse_dictionary(dur_dict)
# This process lets you hear what the network would recieve if trained on the converted midi file.
# Helpful for understanding what patterns are accessible to the network.
notes = midi.read_midi_file(source_filename, verbose=True)
notes = process.convert_notes_to_tokens(notes, pitch_dict, step_dict, dur_dict, verbose=True)
process.convert_tokens_to_notes(notes, pitch_rev_dict, step_rev_dict, dur_rev_dict)
midi.write_midi_file(notes, output_filename)
print('Done.')