Does MidiFile::readFrom make an entire representation of the InputStream's content?


#1

I just had a look at the source code and it seems that the entire content of the given stream (header, tracks, note) will be parsed once the method is done (which would be a good news for me!).
If true, there’s one thing that bugs me though. The parameter isn’t const… and I cannot figure out why?


#2

Weill it needs to be const as it changes the behaviour/state of the MidiFile instance. For example, before calling MidiFile::readFrom, MidiFile::getNumTracks will return 0 - after it will return the number of tracks in the file.


#3

I said the parameter isn’t const not the method. Although I realize InputStream is likely a read-only entity per se so writing a const here would be superfluous.

But is this stream reused when parsing the MidiMessageSequence afterwards or was everything parsed beforehand and we can forget this InputStream?


#4

Well the InputStream is read-only but the InputStream will still change it’s state: for example the file position will be changed when reading.


#5

Right but still doesn’t answer my main question: can I consider this InputStream is no longer useful for parsing my object once it’s been read?


#6

I don’t really understand your question. If your InputStream is positionable just set it back to the beginning of the stream with InputStream::setPosition - you can then re-use it.


#7

Can I drop the stream after I called readFrom? In other terms, is the whole content fully read and structured as MidiMessageSequences after this method so that I can forget that stream and release it?