如何修复JUCE中的Midi inputfilestream错误?

时间:2019-05-05 22:04:22

标签: readfile midi juce

我正在尝试在JUCE中将midi文件读取为一个序列,但是当我运行它时,出现错误,表明我的输入文件流有问题。

我从音频应用程序模板开始,并在getNextBlock()函数中编写了midi读取代码。

File midiPath("/Desktop/input.midi");
FileInputStream myStream(midiPath);
MidiFile midifile;
midifile.readFrom(myStream);
int NumofTrack = midifile.getNumTracks();
std::cout<<"The track number:"<<NumofTrack<<std::end;

我只想在JUCE中测试readin函数,但它不起作用。错误显示为“ juce_FileInputStream.cpp”:

int64 FileInputStream::getTotalLength()
{
    // You should always check that a stream opened successfully before using it!
    jassert (openedOk());              <--  errror here
    ...

1 个答案:

答案 0 :(得分:0)

尝试:

File midiPath = File::getSpecialLocation(File::SpecialLocationType::userDesktopDirectory).getChildFile("input.midi");
FileInputStream myStream(midiPath);
MidiFile midifile;
midifile.readFrom(myStream);
int NumofTrack = midifile.getNumTracks();
std::cout<<"The track number:"<<NumofTrack<<std::end;