michthom / MIDI-to-CNC

Python script to "play" a *.SMF/*.mid file on a 3-axis CNC machine
GNU General Public License v2.0
50 stars 42 forks source link

Index error #4

Closed Darker closed 6 years ago

Darker commented 6 years ago

Command:

"python2.7.exe" mid2cnc.py --machine prusa --infile duke3D.mid --outfile duke3d.gcode --verbose

Error:

Traceback (most recent call last):
  File "mid2cnc.py", line 571, in <module>
    main(sys.argv)
  File "mid2cnc.py", line 358, in main
    midi = midiparser.File(args.infile.name)
  File "C:\MYSELF\programing\python\MIDI-to-CNC\lib\midiparser.py", line 134, in __init__
    self.read(str)
  File "C:\MYSELF\programing\python\MIDI-to-CNC\lib\midiparser.py", line 150, in read
    str = track.read(str)
  File "C:\MYSELF\programing\python\MIDI-to-CNC\lib\midiparser.py", line 169, in read
    track_str = event.read(prev_absolute, prev_status, track_str)
  File "C:\MYSELF\programing\python\MIDI-to-CNC\lib\midiparser.py", line 246, in read
    self.detail.tempo, str  = getNumber(str, length)
  File "C:\MYSELF\programing\python\MIDI-to-CNC\lib\midiparser.py", line 101, in getNumber
    sum = (sum << 8) + ord(theString[i])
IndexError: string index out of range

Happens with the attached file.

duke3D.zip

michthom commented 6 years ago

Thanks, but this seems to be input-dependent. Have you found problems with lots of other .mid files? Might be there's unusual data in your Duke3D MIDI file? If you find what's triggering the crash and submit a pull request for a patch I'll happily look at it for inclusion.

michthom commented 6 years ago

Also - have you added a machine definition for the Prusa? In which case again I'd appreciate a patch to merge.

mid2cnc.py: error: argument -machine/--machine: invalid choice: 'prusa' (choose from 'cupcake', 'custom', 'shapercube', 'thingomatic', 'ultimaker')

michthom commented 6 years ago

Sure enough, the data in your file is borking the getNumber function: It's trying to interpret 'eserved.�/' as an integer and coming up with 31397491531686463751220834048 before it dies.

michthom commented 6 years ago

As per Valentin's pull request, you may want to see if this merge has fixed the issue you reported? If so the thanks go entirely to Valentin!

michthom commented 6 years ago

Closing as I've heard nothing further.