Binary data files consist of three main components: (1) a two- or four-byte word count, (2) followed by a list of items and, and (3) ending in a file trailer. Below is an example binary file shown as hexadecimal numbers. The colors highlight the three main components of the file:
19 00 00 00 C0 40 00 00 00 41 00 00 80 3F 00 00 80 3F 00 00 00 00 00 00 00 00 00 00 70 42 00 00 40 40 00 00 40 40 00 00 80 3F 00 00 00 40 00 00 E0 40 00 00 80 3F 00 00 80 3F 00 00 60 41 00 00 40 40 00 00 30 41 00 00 00 00 00 00 80 3F 00 00 00 00 01 00 00 00 00 00 40 40 00 00 00 00 00 00 A0 40 00 3C 1C C6 |
1. Word count
The first value in a binary SCORE file is a count of the four-byte words which follow in the file. In the MS-DOS versions of SCORE, this value is always a two-byte little-endian unsigned short int. Note however that the Windows version of SCORE can handle large page sizes, so if the word count exceeds 216–1, then the byte-width of this word count will be changed to 4. The word count (× 4) is equivalent to the file size minus two or four bytes, so this value serves little purpose other than to verify the the data file has the expected number bytes.In the example data, 19 00 is the hexadecimal number 0019h which is equivalent to the decimal number 25. This means that there are 25 × 4 = 100 bytes in the data file following this number. Notice that all values are little-endian, so the least significant byte in the data field occurs first.
2. SCORE item list
Following the word count field at the start of the file, a sequence of SCORE items are given in the main body of the file. Each score item starts with a four-byte value indicating the number of parameters to follow for the item. All values (the initial parameter count and item parameters) are encoded as IEEE-754 32-bit floating point numbers. Below is a parsing of the SCORE item list hex bytes into individual words along with their decimal equivalents and meanings.
Hex bytes | Decimal | Meaning |
---|---|---|
00 00 C0 40 | 6.0 | Number of parameters in next item entry |
00 00 00 41 | 8.0 | P1: item is a staff |
00 00 80 3F | 1.0 | P2: staff number |
00 00 80 3F | 1.0 | P3: left horizontal position |
00 00 00 00 | 0.0 | P4: vertical position (default vertical position) |
00 00 00 00 | 0.0 | P5: size (default size) |
00 00 70 42 | 60.0 | P6: right horizontal position |
00 00 40 40 | 3.0 | Number of parameters in next item entry |
00 00 40 40 | 3.0 | P1: item is a clef (default treble clef) |
00 00 80 3F | 1.0 | P2: staff number |
00 00 00 40 | 2.0 | P3: horizontal position |
00 00 E0 40 | 7.0 | Number of parameters in next item entry |
00 00 80 3F | 1.0 | P1: item is a note |
00 00 80 3F | 1.0 | P2: staff number |
00 00 60 41 | 14.0 | P3: horizontal position |
00 00 40 40 | 3.0 | P4: vertical position |
00 00 30 41 | 11.0 | P5: stem direction/accidental (10=stem up + 1=flat) |
00 00 00 00 | 0.0 | P6: notehead type (solid black) |
00 00 80 3F | 1.0 | P7: duration |
The equivalent PMX data for the example data is:
|
And the resulting graphic representation of the data:
|
Text items (P1=16) and Imported EPS files (P1=15) contain a variable length text parameter. This is encoded in binary files by padding the end of the string with spaces (or anything else really) so that the byte count of the string parameter is divisible by 4 (the word size).
3. Trailer
The binary file trailer starts when 0.0 is encountered in the expected position of an item parameter count. However, the trailer is typically read from the end of the file backwards. The last number in a binary file is the floating-point number –9999.0. Then the penultimate value is the word count within the trailer. This count also includes the count field itself, unlike the parameter count fields in the mail body of the data (or you could consider the –9999.0 to be counted rather than the trailer word count field if you like). Before the word count field comes a field indicating the measurement units, either 0.0 for inches or 1.0 for centimeters (this is needed for certain parameter configurations of staff items). Before this is the program version number, preceded by the program serial number. If more parameters were to be added to the trailer, the trailer word count would increase, and the extra parameters would be immediately after the initial 0.0 value at the start of the trailer. If more parameters were to be added to the trailer, the trailer word count would increase, and the extra parameters would be immediately after the initial 0.0 value at the start of the trailer. If more parameters were to be added to the trailer, the trailer word count would increase, and the extra parameters would be immediately after the initial 0.0 value at the start of the trailer.
Hex bytes | Decimal | Meaning |
---|---|---|
00 00 00 00 | 0.0 | Trailer byte 5: beginning of trailer. Must be 0.0, which indicates that there are no more items. The number of parameters in the footer is given as the penultimate number in the file. |
01 00 00 00 | 1. | Trailer byte 4: serial number (32-bit integer) |
00 00 40 40 | 3.0 | Trailer byte 3: program version number |
00 00 00 00 | 0.0 | Trailer byte 2: measurement units (0.0=inches/1.0=centimeters) |
00 00 a0 40 | 5.0 | Trailer byte 1: Word count in trailer (including this one) |
00 3c 1c c6 | -9999.0 | End of file/trailer marker, always -9999.0 |