[seq24-users] longs, ints, and bpm
Brought to you by:
rcbuse
|
From: <seq...@li...> - 2005-12-03 01:21:27
|
Hi,
I just noticed bpm wasn't being restored when loading saved seq24
files. This was because I'm running it on a 64-bit platform. When saving
the (long) bpm value, seq24 explicitly writes 4 bytes. (This is fine,
I'm not likely to have bpm over 2^32 :-) However, when reading
back the value from the end of saved file, seq24 does the following
check:
if ((file_size - m_pos) > (int) sizeof (unsigned long))
/* Get ID + Length */
ID =3D read_long ();
if (ID =3D=3D c_bpmtag)
{
....
(in midifile.cpp)
This won't work, because here unsigned long is 8 bytes, and there are
exactly 8 bytes left in the file (4 for the c_bpmtag, and 4 for the bpm
value itself.)
Therefore I changed this to "sizeof (unsigned int)", and now it
works. (I also modified read_long() and write_long() to explicitly
cast the read and written values from and to unsigned int, but I think
that was probably unnecessary - I was still looking for the problem
at that stage..)
If in the future a different long is stored at the end of the file, the
problem will resurface, I guess. But if read_ and write_long()
were changed to read_ and write_int32() or somesuch, things
would look safer for 64-bit use...
Cheers,
- Pete.
|