Reading and Playing a midi file


#1

Howdy

I'll try to keep my questions organised here regarding opening and playing a midi file.

First, and this is likely due to my misunderstanding, but why won't this work?

in my header file...

File fileInput; //the file object used to create the midifile
MidiFile midiFileInput; //the midifile to manipulate in code

Then in my constructor...

fileInput = File::getCurrentWorkingDirectory().getChildFile("../../../../Resources/testmidi.mid");
midiFileInput.readFrom(fileInput.createInputStream());

This gives me the error

Non-const lvalue reference to type 'juce::InputStream' cannot bind to a temporary of type 'juce::FileInputStream *'

I'm not sure exactly what this means, but would appreciate a little heads up or point in the right direction.

I have found a similar thread I thought I could pull some info out of, but it is very old, and uses the 'new' and 'T' paradigms I have been told to stay away form in Juce....so I am wary to try to learn from that example (http://www.juce.com/forum/topic/playing-midi-file).

If anyone could help me clear up my misunderstanding, I would appreciate it.

Thank yall


#2

Well you're passing a pointer where a reference is required.. (and leaking the file stream too).

If you're struggling with the difference between pointers and references, or don't understand how to manage the lifetime of objects, then I'd recommend spending some time on basic C++ tutorials - you're not going to get very far unless you understand how the language works!


#3

Thanks Jules - you are right and your tip got me going in the right direction. I do get the basic understanding of the difference, I just need the practice like this to keep driving it home. Thank you again, this is great to learn.

 

As for the leak, I was able to fix it by declaring the FileInputStream in the header as a scoped pointer.

 

Thanks yall. I have questions regarding midiOutputs which I will ask once I try with it some more.