Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load MIDI file #149

Closed
CNelias opened this issue Oct 19, 2021 · 15 comments · Fixed by #150
Closed

Unable to load MIDI file #149

CNelias opened this issue Oct 19, 2021 · 15 comments · Fixed by #150

Comments

@CNelias
Copy link
Member

CNelias commented Oct 19, 2021

When I run load(filename), or load(File{format"MIDI"}(filename)) with filename being the path to the file, I get the following errors respectively:

ERROR: MethodError: no method matching load(::String)
Closest candidates are:
  load(::FileIO.File{FileIO.DataFormat{:MIDI}}) at C:\Users\cnelias\.julia\packages\MIDI\tVTq4\src\io.jl:7
  load(::FileIO.Stream{FileIO.DataFormat{:MIDI}, IOtype} where IOtype<:IO) at C:\Users\cnelias\.julia\packages\MIDI\tVTq4\src\io.jl:14
Stacktrace:
 [1] top-level scope
   @ none:1
ERROR: LoadError: UndefVarError: @format_str not defined
in expression starting at none:1

I am using the version 1.12.5
Is the path to the file not a valid argument anymore? If so, it would be helpful to include in the doc, since it still mentions the depreciated readMIDIFile function in all examples.

@Datseris
Copy link
Member

Latest stable MIDI.jl is v2.0.2 can you first update and try again? I don't think there are any breaking changes that would affect you, unless you were using track events directly.

@Datseris
Copy link
Member

Oh yeah, sorry about the docs. I'll open a Pull Request now. We forgot to update that part.... :D

@Datseris
Copy link
Member

ok docs updated, there was actually a pr open

@CNelias
Copy link
Member Author

CNelias commented Oct 20, 2021

Latest stable MIDI.jl is v2.0.2 can you first update and try again? I don't think there are any breaking changes that would affect you, unless you were using track events directly.

For some reason, update MIDI just left me with the 1.12.5 version like before. There must be another issue with my Julia installation preventing the update to the latest version.

@CNelias
Copy link
Member Author

CNelias commented Oct 20, 2021

On a fresh environment where the latest version installs and compiles correctly, I get the same errors.

load(File{format"MIDI"}(filename)) throws

LoadError: MethodError: no method matching load(::String)
Closest candidates are:
  load(!Matched::FileIO.File{FileIO.DataFormat{:MIDI}, Name} where Name) at C:\Users\cnelias\.julia\packages\MIDI\zWmtt\src\io.jl:10
  load(!Matched::FileIO.Stream{FileIO.DataFormat{:MIDI}, IOtype, Name} where {IOtype<:IO, Name}) at C:\Users\cnelias\.julia\packages\MIDI\zWmtt\src\io.jl:17
in expression starting at C:\Users\cnelias\ownCloud\PSD project\src\extract_data.jl:175
get_monophonic_CSV(file::String, datadir::String, writedir::String; grid::StepRange{Rational{Int64}, Rational{Int64}}) at extract_data.jl:166
get_monophonic_CSV(file::String, datadir::String, writedir::String) at extract_data.jl:166
top-level scope at extract_data.jl:175
eval at boot.jl:360 [inlined]
include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String) at loading.jl:1116

If I use the FileIO package, then I get the following error:

LoadError: KeyError: key 0x54 not found
Stacktrace:
  [1] getindex
    @ .\dict.jl:482 [inlined]
  [2] readmetaevent(dT::Int64, f::IOStream)
    @ MIDI C:\Users\cnelias\.julia\packages\MIDI\zWmtt\src\trackevent.jl:37
  [3] readtrack(f::IOStream)
    @ MIDI C:\Users\cnelias\.julia\packages\MIDI\zWmtt\src\miditrack.jl:62
  [4] #40
    @ .\none:0 [inlined]
  [5] iterate
    @ .\generator.jl:47 [inlined]
  [6] collect(itr::Base.Generator{UnitRange{Int64}, MIDI.var"#40#41"{Stream{DataFormat{:MIDI}, IOStream, String}}})
    @ Base .\array.jl:678
  [7] load(s::Stream{DataFormat{:MIDI}, IOStream, String})
    @ MIDI C:\Users\cnelias\.julia\packages\MIDI\zWmtt\src\io.jl:30
  [8] #38
    @ C:\Users\cnelias\.julia\packages\MIDI\zWmtt\src\io.jl:13 [inlined]
  [9] open(f::MIDI.var"#38#39", args::File{DataFormat{:MIDI}, String}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base .\io.jl:330
 [10] open
    @ .\io.jl:328 [inlined]
 [11] load(f::File{DataFormat{:MIDI}, String})
    @ MIDI C:\Users\cnelias\.julia\packages\MIDI\zWmtt\src\io.jl:11
 [12] #invokelatest#2
    @ .\essentials.jl:708 [inlined]
 [13] invokelatest
    @ .\essentials.jl:706 [inlined]
 [14] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:219
 [15] action
    @ C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:197 [inlined]
 [16] load(::FileIO.Formatted; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:120
 [17] load
    @ C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:117 [inlined]
 [18] get_monophonic_CSV(file::String, datadir::String, writedir::String; grid::StepRange{Rational{Int64}, Rational{Int64}})
    @ Main C:\Users\cnelias\ownCloud\PSD project\src\extract_data.jl:168
 [19] get_monophonic_CSV(file::String, datadir::String, writedir::String)
    @ Main C:\Users\cnelias\ownCloud\PSD project\src\extract_data.jl:167
 [20] top-level scope
    @ C:\Users\cnelias\ownCloud\PSD project\src\extract_data.jl:177
in expression starting at C:\Users\cnelias\ownCloud\PSD project\src\extract_data.jl:177
handle_error(e::KeyError, q::Base.PkgId, bt::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}}) at error_handling.jl:61
handle_exceptions(exceptions::Vector{Tuple{Any, Union{Base.PkgId, Module}, Vector{T} where T}}, action::String) at error_handling.jl:56
action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) at loadsave.jl:228
action at loadsave.jl:197 [inlined]
load(::FileIO.Formatted; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) at loadsave.jl:120
load at loadsave.jl:117 [inlined]
get_monophonic_CSV(file::String, datadir::String, writedir::String; grid::StepRange{Rational{Int64}, Rational{Int64}}) at extract_data.jl:168
get_monophonic_CSV(file::String, datadir::String, writedir::String) at extract_data.jl:167
top-level scope at extract_data.jl:177
eval at boot.jl:360 [inlined]
include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String) at loading.jl:1116

also,
load(filename) errors with

LoadError: UndefVarError: load not defined

@Datseris
Copy link
Member

I'm a bit confused what's going on. As you can see in the tests, using MIDI; load(file) works. See here: https://github.com/JuliaMusic/MIDI.jl/blob/master/test/midiio.jl#L6

Can you please make a Minimal Working Example? A full, self contained, runnable piece of code that replicates the problem? Also please attach the file you are trying to load.

@CNelias
Copy link
Member Author

CNelias commented Oct 20, 2021

Here is an example:

using MIDI
filepath = "C:\\Users\\cnelias\\ownCloud\\PSD project\\data\\raw\\movements\\Bach_cello_bwv-1007_1.mid"
midi = load(filepath)
ERROR: UndefVarError: load not defined
Stacktrace:
 [1] top-level scope
   @ none:1

Here is the file Bach_cello_bwv-1007_1.zip

@Datseris
Copy link
Member

I'll have a look by tonight, thanks.

@Datseris
Copy link
Member

Alright, so the problem is, you need to be using FileIO as well to access save.
so using FileIO, MIDI. Apparently this is a requirement from the file IO. What I'll do now in a new PR is bring back the old functions readMIDIFile. This way, if someone wants to use the load syntax, then they have to use FileIO, but otherwise, they can just use MIDI and then use readMIDIFile.

@Datseris
Copy link
Member

So, just to be clear: you don't need to use FileIO. Just using MIDI and then load(file) will just work now after #150

@CNelias
Copy link
Member Author

CNelias commented Oct 25, 2021

@Datseris load(file) still throws a KeyError, even after updating the latest version. Any idea why that might be?

LoadError: KeyError: key 0x54 not found
Stacktrace:
  [1] getindex
    @ .\dict.jl:482 [inlined]
  [2] readmetaevent(dT::Int64, f::IOStream)
    @ MIDI C:\Users\cnelias\.julia\packages\MIDI\VaZGx\src\trackevent.jl:35
  [3] readtrack(f::IOStream)
    @ MIDI C:\Users\cnelias\.julia\packages\MIDI\VaZGx\src\miditrack.jl:59
  [4] #40
    @ .\none:0 [inlined]
  [5] iterate
    @ .\generator.jl:47 [inlined]
  [6] collect(itr::Base.Generator{UnitRange{Int64}, MIDI.var"#40#41"{FileIO.Stream{FileIO.DataFormat{:MIDI}, IOStream, String}}})
    @ Base .\array.jl:678
  [7] fileio_load(s::FileIO.Stream{FileIO.DataFormat{:MIDI}, IOStream, String})
    @ MIDI C:\Users\cnelias\.julia\packages\MIDI\VaZGx\src\io.jl:27
  [8] #invokelatest#2
    @ .\essentials.jl:708 [inlined]
  [9] invokelatest
    @ .\essentials.jl:706 [inlined]
 [10] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:219
 [11] action
    @ C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:197 [inlined]
 [12] load(::FileIO.Formatted; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:120
 [13] load
    @ C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:117 [inlined]
 [14] #38
    @ C:\Users\cnelias\.julia\packages\MIDI\VaZGx\src\io.jl:10 [inlined]
 [15] open(f::MIDI.var"#38#39", args::FileIO.File{FileIO.DataFormat{:MIDI}, String}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base .\io.jl:330
 [16] open
    @ .\io.jl:328 [inlined]
 [17] fileio_load(f::FileIO.File{FileIO.DataFormat{:MIDI}, String})
    @ MIDI C:\Users\cnelias\.julia\packages\MIDI\VaZGx\src\io.jl:8
 [18] #invokelatest#2
    @ .\essentials.jl:708 [inlined]
 [19] invokelatest
    @ .\essentials.jl:706 [inlined]
 [20] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:219
 [21] action
    @ C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:197 [inlined]
 [22] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::Symbol, ::String; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:185
 [23] action
    @ C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:185 [inlined]
 [24] load(::String; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:113
 [25] load(::String)
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:110
 [26] top-level scope
    @ C:\Users\cnelias\ownCloud\code\julia\etude.jl:64
Stacktrace:
  [1] handle_error(e::KeyError, q::Base.PkgId, bt::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\error_handling.jl:61
  [2] handle_exceptions(exceptions::Vector{Tuple{Any, Union{Base.PkgId, Module}, Vector{T} where T}}, action::String)
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\error_handling.jl:56
  [3] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:228
  [4] action
    @ C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:197 [inlined]
  [5] load(::FileIO.Formatted; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:120
  [6] load
    @ C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:117 [inlined]
  [7] #38
    @ C:\Users\cnelias\.julia\packages\MIDI\VaZGx\src\io.jl:10 [inlined]
  [8] open(f::MIDI.var"#38#39", args::FileIO.File{FileIO.DataFormat{:MIDI}, String}; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Base .\io.jl:330
  [9] open
    @ .\io.jl:328 [inlined]
 [10] fileio_load(f::FileIO.File{FileIO.DataFormat{:MIDI}, String})
    @ MIDI C:\Users\cnelias\.julia\packages\MIDI\VaZGx\src\io.jl:8
 [11] #invokelatest#2
    @ .\essentials.jl:708 [inlined]
 [12] invokelatest
    @ .\essentials.jl:706 [inlined]
 [13] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:219
 [14] action
    @ C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:197 [inlined]
 [15] action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::Symbol, ::String; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:185
 [16] action
    @ C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:185 [inlined]
 [17] load(::String; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:113
 [18] load(::String)
    @ FileIO C:\Users\cnelias\.julia\packages\FileIO\DNKwN\src\loadsave.jl:110
 [19] top-level scope
    @ C:\Users\cnelias\ownCloud\code\julia\etude.jl:64
in expression starting at C:\Users\cnelias\ownCloud\code\julia\etude.jl:63
handle_error(e::CapturedException, q::Base.PkgId, bt::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}}) at error_handling.jl:61
handle_exceptions(exceptions::Vector{Tuple{Any, Union{Base.PkgId, Module}, Vector{T} where T}}, action::String) at error_handling.jl:56
action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::FileIO.Formatted; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) at loadsave.jl:228
action at loadsave.jl:197 [inlined]
action(::Symbol, ::Vector{Union{Base.PkgId, Module}}, ::Symbol, ::String; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) at loadsave.jl:185
action at loadsave.jl:185 [inlined]
load(::String; options::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) at loadsave.jl:113
load(::String) at loadsave.jl:110
top-level scope at etude.jl:64
eval at boot.jl:360 [inlined]
include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String) at loading.jl:1116

@Datseris
Copy link
Member

Hm, I think this might be specific to your own file. My guess is that there is an event type we are missing here: https://github.com/JuliaMusic/MIDI.jl/blob/master/src/events.jl

Can you check? And if we are missing your special event, then please just open a PR that incorporates this event. It is as simple as adding one mapping for 0x54 .

@Datseris
Copy link
Member

I can't find the status byte 0x54 anywhere in https://www.recordingblogs.com/wiki/status-byte-of-a-midi-message . Are you sure the MIDI file is valid?

@Datseris
Copy link
Member

Ah okay it is the SMPTE message : https://www.recordingblogs.com/wiki/midi-smpte-offset-meta-message Haha infact we have a TODO in the events.jl to add this. Okay so @johncwok this is a simple PR once you have it open I can review and merge.

@CNelias
Copy link
Member Author

CNelias commented Oct 26, 2021

@Datseris Done. Please go ahead with the review & merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants