fix pause duration
This commit is contained in:
parent
4c6e790127
commit
571e8e559a
|
@ -20,7 +20,7 @@ pitches = ["c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"]
|
|||
frequencies = {
|
||||
f"{pitches[i % 12]}{i // 12 + 3}": 2 ** (i / 12) * 130.81 for i in range(36)
|
||||
}
|
||||
# duration of 1/16th beat
|
||||
# duration of 1/16th beat in seconds
|
||||
base_duration = 60 / args.bpm / 16
|
||||
|
||||
with open(args.output, "w") as f:
|
||||
|
@ -44,7 +44,9 @@ with open(args.output, "w") as f:
|
|||
pause = int(pause)
|
||||
if duration < 1 or pause < -1:
|
||||
sys.exit("duration/pause are integer multiples of 1/16th beat")
|
||||
# feedrate in mm per minute
|
||||
feedrate = int(frequency * 60 / args.steps_per_mm)
|
||||
# length in mm
|
||||
length = duration * base_duration / 60 * feedrate
|
||||
position += -length if position > 100 else length
|
||||
if position < 0 or position > 200:
|
||||
|
@ -52,6 +54,6 @@ with open(args.output, "w") as f:
|
|||
f.write(f"; {pitch},{duration},{pause}\n")
|
||||
f.write(f"G0 X{position:.6f} Y{position:.6f} F{feedrate}\n")
|
||||
if pause != -1:
|
||||
pause_ms = int(pause * base_duration)
|
||||
pause_ms = int(pause * base_duration * 1000)
|
||||
f.write(f"G4 P{pause_ms}\n")
|
||||
f.write("G4 S2 ; wait 2 seconds\n")
|
||||
|
|
Loading…
Reference in a new issue