PedroAlvesV/LuaMidi

Error with 'get_MIDI_tracks' -> 'last_control_byte' not getting updated from its initailizer 'false'

Opened this issue · 0 comments

I've tried a bunch of different midi files with 'get_MIDI_tracks' and they've all thrown this error.
In short, this library does not work with all .mid files. Or it's looking for specific formatting?

here's an archive of the project i'm working on -> midi-visualizer.zip
run lua plain-lua-problem-example.lua to reproduce the problem I having.
plain-lua-problem-example.lua just looks like this...

LuaMidi = require("LuaMidi")
tracks = LuaMidi.get_MIDI_tracks("112561.mid")

I've archived the whole project so you can see the midi files I'm using and such

Here's the error

lua: ./LuaMidi/bit/native_bitwise.lua:3: attempt to perform bitwise operation on a boolean value (local 'a')
stack traceback:
	./LuaMidi/bit/native_bitwise.lua:3: in function 'LuaMidi.bit.native_bitwise.band'
	./LuaMidi.lua:233: in function 'LuaMidi.get_MIDI_tracks'
	plain-lua-problem-example.lua:3: in main chunk
	[C]: in ?

the line from 'get_MIDI_tracks'

...
local event = EVENTS[band(last_control_byte, 0xF0)]({
  last_control_byte,
  raw_track[i],
  raw_track[i+1],
}, current_timestamp)
...

the 'band' function from 'numberlua.lua'

...
function M.band(a,b) return ((a+b) - bxor(a,b))/2 end
local band = M.band
...

By running some print tests it looks like 'last_control_byte' never gets set to something besides its initializer 'false'.
I modified get_midi_tacks so could see what the function was doing.

elliot@elliots-computer:~/in-progress/love/midi-visualizer$ lua plain-lua-problem-example.lua 
LuaMidi.get_MIDI_tracks(112561.mid)
  while i:1 <= #raw_track:42714 ...... raw_track[i]: 0
    last_control_byte: false
    raw_track[i] == 0xFF -- METADATA
      raw_track[i+1]: 3
      subtype: Name
  while i:13 <= #raw_track:42714 ...... raw_track[i]: 0
    last_control_byte: false
    raw_track[i] == 0xFF -- METADATA
      raw_track[i+1]: 84
      subtype: SMPTE offset
  while i:22 <= #raw_track:42714 ...... raw_track[i]: 0
    last_control_byte: false
    raw_track[i] == 0xFF -- METADATA
      raw_track[i+1]: 88
      subtype: Time Signature
  while i:30 <= #raw_track:42714 ...... raw_track[i]: 0
    last_control_byte: false
    raw_track[i] == 0xFF -- METADATA
      raw_track[i+1]: 89
      subtype: Key Signature
  while i:36 <= #raw_track:42714 ...... raw_track[i]: 0
    last_control_byte: false
    raw_track[i] == 0xFF -- METADATA
      raw_track[i+1]: 81
      subtype: Tempo
  while i:43 <= #raw_track:42714 ...... raw_track[i]: 0
    last_control_byte: false
    raw_track[i] == 0xFF -- METADATA
      raw_track[i+1]: 33
      subtype: Midi Port
  while i:48 <= #raw_track:42714 ...... raw_track[i]: 0
    last_control_byte: false
  while i:50 <= #raw_track:42714 ...... raw_track[i]: 73
    last_control_byte: false
    raw_track[i] < 0x80 -- RUNNING STATUS
      last_control_byte: false
lua: ./LuaMidi/bit/native_bitwise.lua:3: attempt to perform bitwise operation on a boolean value (local 'a')
stack traceback:
	./LuaMidi/bit/native_bitwise.lua:3: in function 'LuaMidi.bit.native_bitwise.band'
	./LuaMidi.lua:249: in function 'LuaMidi.get_MIDI_tracks'
	plain-lua-problem-example.lua:3: in main chunk
	[C]: in ?

Now I don't know what this means, i don't know anything about how .mid files are formatted.