Midifile View on GitHub

Binasc class

home   »   documentation   »   classes

Description</summary> The Binasc class manages conversion between ASCII representation of bytes and their conversion into bytes. This class is used by the MidiFile class to allow for Standard MIDI Files to be read/written in an ASCII format. Here is a low-level representation of a Standard MIDI file as hex bytes: ``` 4d 54 68 64 00 00 00 06 00 01 00 03 00 78 4d 54 72 6b 00 00 00 04 00 ff 2f 00 4d 54 72 6b 00 00 00 76 00 90 48 40 78 80 48 40 00 90 48 40 78 80 48 40 00 90 4f 40 78 80 4f 40 00 90 4f 40 78 80 4f 40 00 90 51 40 78 80 51 40 00 90 51 40 78 80 51 40 00 90 4f 40 81 70 80 4f 40 00 90 4d 40 78 80 4d 40 00 90 4d 40 78 80 4d 40 00 90 4c 40 78 80 4c 40 00 90 4c 40 78 80 4c 40 00 90 4a 40 78 80 4a 40 00 90 4a 40 78 80 4a 40 00 90 48 40 81 70 80 48 40 00 ff 2f 00 4d 54 72 6b 00 00 00 7d 00 90 30 40 78 80 30 40 00 90 3c 40 78 80 3c 40 00 90 40 40 78 80 40 40 00 90 3c 40 78 80 3c 40 00 90 41 40 78 80 41 40 00 90 3c 40 78 80 3c 40 00 90 40 40 78 80 40 40 00 90 3c 40 78 80 3c 40 00 90 3e 40 78 80 3e 40 00 90 3b 40 78 80 3b 40 00 90 3c 40 78 80 3c 40 00 90 39 40 78 80 39 40 00 90 35 40 78 80 35 40 00 90 37 40 78 80 37 40 00 90 30 40 81 70 80 30 40 00 ff 2f 00 ``` Even though this data is all ASCII characters, it can be parsed transparently by the MidiFile::read() function. The Binasc ASCII byte code syntax can deal with bytes in different textual formats. Here is are equivalent ASCII byte codes in a higher-level representation that can also be read by MidiFile::read(), making the structure of the binary MIDI file more apparent: ``` +M +T +h +d 4'6 2'1 2'3 2'120 ; TRACK 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +M +T +r +k 4'4 v0 ff 2f '0 ; TRACK 1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +M +T +r +k 4'118 v0 90 '72 '64 v120 80 '72 '64 v0 90 '72 '64 v120 80 '72 '64 v0 90 '79 '64 v120 80 '79 '64 v0 90 '79 '64 v120 80 '79 '64 v0 90 '81 '64 v120 80 '81 '64 v0 90 '81 '64 v120 80 '81 '64 v0 90 '79 '64 v240 80 '79 '64 v0 90 '77 '64 v120 80 '77 '64 v0 90 '77 '64 v120 80 '77 '64 v0 90 '76 '64 v120 80 '76 '64 v0 90 '76 '64 v120 80 '76 '64 v0 90 '74 '64 v120 80 '74 '64 v0 90 '74 '64 v120 80 '74 '64 v0 90 '72 '64 v240 80 '72 '64 v0 ff 2f '0 ; TRACK 2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +M +T +r +k 4'125 v0 90 '48 '64 v120 80 '48 '64 v0 90 '60 '64 v120 80 '60 '64 v0 90 '64 '64 v120 80 '64 '64 v0 90 '60 '64 v120 80 '60 '64 v0 90 '65 '64 v120 80 '65 '64 v0 90 '60 '64 v120 80 '60 '64 v0 90 '64 '64 v120 80 '64 '64 v0 90 '60 '64 v120 80 '60 '64 v0 90 '62 '64 v120 80 '62 '64 v0 90 '59 '64 v120 80 '59 '64 v0 90 '60 '64 v120 80 '60 '64 v0 90 '57 '64 v120 80 '57 '64 v0 90 '53 '64 v120 80 '53 '64 v0 90 '55 '64 v120 80 '55 '64 v0 90 '48 '64 v240 80 '48 '64 v0 ff 2f '0 ``` A "+" in front of a character will use the ASCII byte code for that letter in the compiled file. 4'6 means create a 4-byte integer in big-endian byte order with the decimal value 6. "v120" for the tick delta times means to convert the decimal value 120 into a variable-length value. A string such as '64 means to store the decimal value 64 into a single output byte. </details> Primary functions ----------------
readFromBinary — Convert ASCII byte codes into a binary file.
writeToBinary — Convert a binary file into ASCII byte codes.
  Fucntions for ASCII printing options ------------------------------------
getBytes — Get hex byte display option.
getComments — Get comment display style for ASCII output.
getLineBytes — Get the maximum number of hex bytes in ASCII output.
getLineLength — Returns the maximum length of an ASCII text line.
getMidi — Get display option for showing ASCII MIDI file markup.
setBytes — Display or not display hex codes in ASCII output.
setComments — Display or not display printable characters as ASCII comments.
setLineBytes — Set the maximum number of hex bytes in ASCII output.
setLineLength — Set the maximum length of an ASCII text line.
setMidi — Set display option for showing ASCII MIDI file markup.
    Keyboard shortcuts for this page:
  • ctrl++/= to open all function documentation entries.
  • ctrl+ to close all documentation.
  • ctrl+eto toggle display of all code examples.
  • shft+click will open documentation for a single method and close all other entries.