-
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
How to support tempo change for many times? #60
Comments
You need to provide an example of the problem, as I do not see it. You can compare to my simple test below. First, here is the musical content: The tempo starts at quarter notes = 60 bpm, then in the second measure changes to 120 bpm. So the quarter notes in the first measure are one second long and in the second measure they are 0.5 seconds long. The total duration of the music is 8 seconds (4 seconds for the first measure, 2 seconds for the second measure and 2 seconds for the last measure). And here is the MIDI file (in ASCII format) representing the above music:
And here is a program to print the total time of the MIDI file, and the start-times of each note: #include "MidiFile.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
using namespace smf;
int main(int argc, char** argv) {
if (argc != 2) {
cerr << "Usage: " << argv[0] << " file.mid" << endl;
exit(1);
}
MidiFile infile;
infile.read(argv[1]);
if (!infile.status()) {
cerr << "Problem reading MIDI file " << argv[1] << endl;
}
infile.joinTracks();
infile.doTimeAnalysis();
cout << "Duration of MIDI file in ticks: "
<< infile.getFileDurationInTicks() << endl;
cout << "Duration of MIDI file in seconds: "
<< infile.getFileDurationInSeconds() << endl;
// Print start times of notes in file:
cout << "Tick\tTime (seconds)\n";
for (int i=0; i<infile[0].getEventCount(); i++) {
if (infile[0][i].isNoteOn()) {
cout << infile[0][i].tick << "\t"
<< infile[0][i].seconds << endl;
}
}
return 0;
} Here is the output of the program using the test MIDI file as input (the ASCII form will be understood by the program):
Compare the time values in the second column to the musical example: The numbers underneath the notes and the numbers in the second column are the same, so the tempo change is correctly handled to calculate the time in seconds throughout the example. |
hello, When reading a midi file, if tempo changes, the absolute time of midi event will go wrong. How can I solve this problem?
The text was updated successfully, but these errors were encountered: