in package pl_win_midi cmpMIDIData does not include track count in MIDI header when created at runtime
Original Reporter info from Mantis: j3llie
-
Reporter name: John Elston
Original Reporter info from Mantis: j3llie
- Reporter name: John Elston
Description:
Creating a MIDIData at runtime then saving to a file does not save a correctly formed MIDI File. A 0 is saved as the number of tracks.
Hexdump of MIDI header from a file
4D 54 68 64 00 00 00 06 00 01 00 00 00 B4
| | This is the track count and should be 00 01 for a single track
Steps to reproduce:
Start a new project
add cmpMidiData to uses
procedure TForm1.ToolButton1Click(Sender: TObject);
var
mf:TMIDIData;
begin
mf:= TMIDIData.create(self);
mf.AddNewTrack(0);
mf.FileName:='test.mid';
mf.Save;
mf.free;
end;
The resulting MIDI file will not have the correct track count in the header. Loading a MIDI file works correctly as the
track count is read from the file header.
Additional information:
I think the problem is related to the line
Assuming one track is created as above
fHeader.nTracks := Swap (NoTracks);
in the function TMidiData.AddNewTrack (i : Integer) : boolean;
Swap (NoTracks); incorecctly returns 0 when is should be 256 (ie swapped value 1)
GetNoTracks correctly returns an integer of value 1
GetNoTracks just returns the fTrackList.count as an integer so swap should work????
As a workaround I got it to work by changing
in cmpMidiData.pas
Change NoTracks property to word
ie
function GetNoTracks : word;
property NoTracks : Word read GetNoTracks;
function TMidiData.GetNoTracks: word;
the swap function now returns 256 and produces a correct file
Mantis conversion info:
- Mantis ID: 36801
- OS: Windows 10
- OS Build: home
- Build: Lazarus 2.0.6 r62129 FPC 3.0.4 x
- Platform: Intel i5
- Version: 2.0.6