-
Notifications
You must be signed in to change notification settings - Fork 136
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
Events are not linked #74
Comments
That should be correct. Here is a test program that I just wrote and tested with the latest verision of the code: #include "MidiFile.h"
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
if (argc < 2) {
cerr << "Usage: " << argv[0] << " filename" << endl;
return 1;
}
smf::MidiFile midi_parser(argv[1]);
if (!midi_parser.status()) {
cerr << "Bad MIDI File" << endl;
return 1;
}
midi_parser.linkNotePairs();
midi_parser.doTimeAnalysis();
for (int i=0; i<midi_parser.getTrackCount(); i++) {
for (int j=0; j<midi_parser[i].getEventCount(); j++) {
if (midi_parser[i][j].isNoteOn()) {
int key = midi_parser[i][j].getKeyNumber();
double time = midi_parser[i][j].seconds;
double duration = midi_parser[i][j].getDurationInSeconds();
cout << "NOTE ON key=" << key
<< "\ttime=" << time
<< "\tdur=" << duration
<< endl;
} else if (midi_parser[i][j].isNoteOff()) {
int key = midi_parser[i][j].getKeyNumber();
double time = midi_parser[i][j].seconds;
cout << "NOTE OFF key=" << key << "\ttime=" << time << endl;
}
}
}
return 0;
} I then tested with two MIDI files using the "0x80" note-off method and the "0x90" method with zero velocity:
the output for the above MIDI file:
Each note is one second long. Using 0x90 (note-on) commands with zero velocity method for note-offs:
And the result of the analysis program is the same, and as expected:
The only think that I can currently think of right now is that the note-on and the note-off are on different channels. Can you also print the channels of the notes? And/or can you post a test MIDI file that has the problem? There is a tool called "binasc.cpp" which will print a MIDI file in the above formats to display in the issues as text. Otherwise you could MIME encode the MIDI file or similar (since I don't seem to be able to attached a MIDI file to issues). |
File: sample_song.zip Binasc:
I am not sure if I am doing something wrong but this is all I could get from binasc. Is there a limit to characters printed or something? I tried viewing through the debugger as well. std::ostringstream os;
os << midi_parser;
std::string s=os.str();
log("%s", s.c_str()); |
What environment are you using? That seems to be the problem. With the truncated text output, it is likely there is a toggle button on the log console to show the entire contents of the output. I was able to print the entire MIDI file using this program in MacOS terminal: #include "MidiFile.h"
#include <iostream>
#include <sstream>
int main(int argc, char** argv) {
if (argc != 2) {
std::cerr << "Error: need one MIDI file as argument" << std::endl;
exit(1);
}
smf::MidiFile midi_parser(argv[1]);
bool status = midi_parser.status();
if (!status) {
std::cerr << "Error: cannot read MIDI file" << std::endl;
exit(1);
}
std::ostringstream os;
os << midi_parser;
std::string s = os.str();
std::cout << s.c_str() << "\n";
return 0;
} Here is the full contents that I get:
|
And here is the output that I am getting for the original test program showing the durations of the notes:
|
The next thing you should do is check the parsing status of the MIDI file. Here is the piece of code from the original test program:
The I suspect that there could be an ASCII/Binary string problem. If you are using this in a Javascript environment that may be the problem. |
The status is fine. Also note this is C++ in an android app. |
Either there is a problem in the Android environment, or there is a bug in the midifile library which is visible in Android but not elsewhere. Try loading this MIDI file (from the attached zip file) to see if a shorter MIDI file behaves any better:
Where the duration of each of the four notes should be 1.0:
|
I think I got it
Issue on the first line edit: Yep it works now |
I do not see how the title of this is related to 0 duration |
In the latest version, duration is always zero. I have tried doing time analysis first.
smf::MidiFile midi_parser(in); midi_parser.linkNotePairs(); midi_parser.doTimeAnalysis();
In the loop:
Sample output:
NOTE ON 49, 272.571792, 0.000000
NOTE ON 53, 272.571792, 0.000000
NOTE ON 56, 272.571792, 0.000000
NOTE OFF 49, 275.013760
NOTE OFF 53, 275.013760
NOTE OFF 56, 275.013760
The text was updated successfully, but these errors were encountered: