student (9) [Avatar] Offline
#1
Hi,
can somebody explain me how to interpret the following tempo change.
I am opening a SMF of format 1. The first event of the one and only track has a status 0 therefore contains a tempo change. data1, data2, and data3 contain the tempo change. ok! With a tempo of 120bpm , set on the basis of a quarter note and with a time signature of 4/4 I get these values:
data1=>7
data2=>161
data3=>32
With a tempo of 100 bpm I get:
data1=>9
data2=>39
data3=>192
I can't find how these numbers change. Also when I change the time signature to 3/4 it does not show in any of the data1,data2,data3. THe numbers are intact. Can it be the midi file that is causing this?
Thanx
student (9) [Avatar] Offline
#2
Re: Tempo Change Interpetation
Sorry, I forgot to add the resolution is set to 96
KUMA (56) [Avatar] Offline
#3
Re: Tempo Change Interpetation
When status is 0, data1, data2, data3 together represent tempo in microseconds per beat.
In your 1st case, data1 is 7=0x07, data2 is 161=0xA1, data3 is 32=0x20, so they represent 0x07A120, which means that the tempo is 500000 microseconds per beat, namely, 120bpm.
Note that tempo data is independent of any other data.
In this context, 'beat' means just a unit; beat is irrelevant to time signature but depends on resolution.
For example, when the resolution is 96, the unit consists of 96 ticks, and if the tempo is 120bpm, ticks should be generated every 500000/96000 microseconds.

By the way, why does your SMF format 1 have only one track? Usually, track 0 of SMF format 1 contains Meta Events only. Have you made your SMF for a specific use?

Incidentally, can you read all the events in your SMF now?
student (9) [Avatar] Offline
#4
Re: Tempo Change Interpetation
Thanks a lot for the help! Its really valuable...
I can read all the events in my SMF file and get the note numbers ok. The weird thing is that if the file has only one note then it doesn't appear anywhere in the track. If it has 2 or more then it is ok. Also I don't know why the midi file has only one track. I used a simple program called mozart to create the midi files I use in my app. I guess I have to use something more reliable. One more thing about the tempo. How do I get the time signature? What is the status byte value? And is it possible for a midi file not to have a time signature...so the default 4/4 will be used.
KUMA (56) [Avatar] Offline
#5
Re: Tempo Change Interpetation
Note, as I said at another thread, that SMF.Load function ignores any Meta Events except Set Tempo, Track Name, and End of Track. In MaxMidi, Midi events and Meta events are treated differently, and there is no room in the tracks attached to a SMF to contain Meta Events.
To get the time signature you need to use ReadMeta function, and if there are 2 or more time signatures, you will need to put the data of the 1st one in an appropriate buffer before getting another one.

You can omit any Meta Event except End of Track to write SMF. Meta Events are irrelevant to play SMF.

To use track 0 of SMF format 1 to contain Meta Events only is not a rule but a practice. I have reffered to the point just to caution you to avoid problems which that will cause.

Concerning SMF and Meta events, you'd better read well chapter 13 of the book.

>The weird thing is that if the file has only one note then it doesn't appear anywhere in the track.

How about the value of GetNumEvents?
student (9) [Avatar] Offline
#6
Re: Tempo Change Interpetation
Sorry for the delay of my reply but I run into some problems with the graphic editor of the program that had to be solved...
Returning to the tempo, if I got it right, a way to calculate every note's duration in termos of quarters etc. is to add the note off of a note with the next note on and divide the sum with the resolution! Since we know that the beat is calculated according to a quarter note we can derive all the other values. Is that right? It seems alright according to my calculations. I sorted out the problem with the track 0. Now I can read different tracks and get all the events.
thanx again for ur time!
KUMA (56) [Avatar] Offline
#7
Re: Tempo Change Interpetation
To calculate a note's duration in ticks, you need to add successively all the timestamps of the events following the corresponding Note On Event up to the corresponding Note Off Event.