-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
40 lines (33 loc) · 1.29 KB
/
main.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
# Imports
import sys
from MidiGcode import midi, gcode
from mido import MidiFile
# Genretates gCode from midifile
def generateGCodeFromMidi(midiFilename, gCodeFilename):
frequencyTimeMatrix = midi.getFrequencyTimeMatrix(midiFilename)
print(frequencyTimeMatrix)
feedratesTimeMatrix = gcode.translateFrequencyTimeMatrixToFeedratesTimeMatrix(frequencyTimeMatrix)
print("\n\n")
print(feedratesTimeMatrix)
gcode.generateGCode(feedratesTimeMatrix, gCodeFilename)
def getFileExtension(filename):
return filename.split('.')[-1]
def main():
if len(sys.argv) != 3:
print("midiToGCode requires two arguments: [midiFilename, gCodeFilename]")
exit(1)
midFileExtension = getFileExtension(sys.argv[1])
if midFileExtension.lower() != "mid":
print("MidiFilename argument had extension ." + midFileExtension + ", expected .mid")
exit(1)
gCodeFileExtension = getFileExtension(sys.argv[2])
if gCodeFileExtension.lower() != "gcode":
print("GcodeFilename argument had extension ." + gCodeFileExtension + ", expected .gcode")
exit(1)
#try:
generateGCodeFromMidi(sys.argv[1], sys.argv[2])
print("gCode generated")
#except Exception as e:
#print("Generation of gcode failed "+str(e))
exit(1)
main()