Note that there are some explanatory texts on larger screens.

plurals
  1. POError apparently raised by not yet executed code
    primarykey
    data
    text
    <p>I'm learning c++ by writing a program to convert MIDI files to <a href="http://lilypond.org" rel="nofollow">Lilypond</a> source files. My program is composed by two main parts:</p> <ul> <li>a MIDI file parser, that creates an object called MidiFile.</li> <li>a converter that takes a MidiFile objects and converts it to a Lilypond source.</li> </ul> <p>Today I've started coding the converter, and while I was testing it a strange error occurred: the program dies after an exception being thrown, more specifically a HeaderError, that means that the header chunk in the MIDI file is not as expected. It wouldn't seem that strange, but this error shows up only if I add a line of code after the buggy code! I add the main() function to better explain myself</p> <pre><code>#include &lt;iostream&gt; #include "midiToLyConverter.hpp" int main(){ // a queue to store notes that have not yet been shut down using MidiToLyConverter::Converter::NoteQueue; // representation of a note using MidiToLyConverter::Converter::Note; // the converter class using MidiToLyConverter::Converter::Converter; // the midifile class using Midi::MidiFile; // representation of a midi track using Midi::MidiTrack; // representation of a midi event using Midi::MidiEvents::Event; Parser::Parser parser = Parser::Parser(); // parser class parser.buildMidiFile(); // builds the midi file from a .mid Midi::MidiFile* midiFile = parser.getMidiFile(); // gets the MidiFile object // iterates over all the tracks in the MidiFile while(midiFile-&gt;hasNext()){ std::cout&lt;&lt; "==========\n"; MidiTrack* track = midiFile-&gt;nextTrack(); // iterates over all events in a track while(track-&gt;hasNext()){ Event* event = track-&gt;nextEvent(); if (event-&gt;getEventType() == Midi::MidiEvents::NOTE_ON || event-&gt;getEventType() == Midi::MidiEvents::NOTE_OFF ) // print the event if it's a note on or off event-&gt;print(); } } return 0; } </code></pre> <p>With my main() like this, everything works properly, but, if I add something between buildMidiFile and the while loop, the function buildMidiFile throws the exception!!! Even if it's a completely unrelated instruction!</p> <pre><code>#include &lt;iostream&gt; #include "midiToLyConverter.hpp" int main(){ using MidiToLyConverter::Converter::NoteQueue; using MidiToLyConverter::Converter::Note; using MidiToLyConverter::Converter::Converter; using Midi::MidiFile; using Midi::MidiTrack; using Midi::MidiEvents::Event; Parser::Parser parser = Parser::Parser(); // parser class parser.buildMidiFile(); // THE EXCEPTION IS THROWN HERE Midi::MidiFile* midiFile = parser.getMidiFile(); // gets the MidiFile object // adding this causes the exception to be thrown by the function // buildMidiFile() called 5 lines above! std::vector&lt;bool&gt;* vec = new std::vector&lt;bool&gt;(); // iterates over all the tracks in the MidiFile while(midiFile-&gt;hasNext()){ std::cout&lt;&lt; "==========\n"; MidiTrack* track = midiFile-&gt;nextTrack(); // iterates over all events in a track while(track-&gt;hasNext()){ Event* event = track-&gt;nextEvent(); if (event-&gt;getEventType() == Midi::MidiEvents::NOTE_ON || event-&gt;getEventType() == Midi::MidiEvents::NOTE_OFF ) // print the event if it's a note on or off event-&gt;print(); } } return 0; } </code></pre> <p>I can't explain myself how this is possible. So if anyone has ideas or advices, all the help would be greatly appreciated :) If it's helpful I can post the source code for other classes and/or functions.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload