<small> This is a Stub article. A Wiki version of Gears should go here. For more information, select the "discussion" tab above so we can best architecture the data. For those who want to start converting, download the Gears pdf [[User:Halkun|Halkun]] 20:18, 5 Mar 2005 == Standard MIDI File (CSTSMF) </small>Format ==
The <B>Standard MIDI File<br /B>(SMF) is a file format used to store MIDI data (plus someother kinds of data typically needed by a sequencer.
== Contents ==This format stores the standard MIDI messages (ie, status bytes with appropriate data bytes)plus a time-stamp for each message (ie, a series of bytes that represent how many clock pulsesto wait before "playing" the event). The format also allows saving information about tempo,time and key signatures, the names of tracks and patterns, and other information typicallyneeded by a sequencer. One SMF can store information for numerous patterns and tracks so that anysequencer can preserve these structures when loading the file.
* [[FF7<B><FONT COLOR=RED>NOTE:</FONT></B> A <B>track</History|History]]B> usually is analogous to one musical part,* [[FF7such as a Trumpet part. A <B>pattern</Engine_basics|Engine Basics]]** Parts B> would be analogous to all of the Enginemusical parts (ie,Trumpet, Drums, Piano, etc) for one song.** Generic Program Flow* [[FF7/Kernel|The Kernel]]format was designed to be generic so that the most important data can be read by all** [[FF7/Kernel/Overview|Kernel Overview]]sequencers. Think of a MIDI file as a musical version of an ASCII text file (except*** Historythat the MIDI file contains binary data), and the various sequencer programs as text editors*** Kernel Functionality** [[FF7/Kernelall capable of reading that file. But, unlike ASCII, MIDI file format saves data in <B>chunks</Memory_management|Memory Management]]B>*** RAM Management(ie, groups of bytes preceded by an ID and size) which can be parsed, loaded, skipped, etc.*** VRAM ManagementTherefore, SMF format is flexible enough for a particular sequencer to store*** PSX CD-ROM managementits own proprietary, "extra" data in such a way that another sequencer won't be confused when** [[FF7/Kernel/Kernelloading the file and can safely ignore this extra stuff that it doesn't need.bin|Kernel.bin]]*** The KERNELFor example, maybe a sequencer wants to save a "flag byte"that indicates whether the user has turned on an audible metronome click.BIN Archive*** The KERNEL2.BIN Archivesequencer can save** [[FF7/Kernel/Low_level_libraries|Low Level Libraries]]this flag byte in such a way that another sequencer can skip this byte without*** PC having to PSX comparisonunderstand what that byte is for. In the future, the SMF format can also be*** Data Archivesextended to include new "official" chunks that all sequencer programs may elect to load and use.**** BIN Archive This can be done without making old data files obsolete, nor making old sequencers no longerable to load the new files. So, the formatis designed to beextensible in a backwardly compatible way.**** [[FF7/LZSS_format| LZSS Archives]]**** [[FF7/LGP_format| LGP Archives]]Of course, SMF files may be used by other MIDI software than just sequencers.*** TexturesSince SMF files can store any and all types of MIDI messages, including System Exclusive**** [[PSXmessages, they may be used to store/TIM_format| TIM texture load data format by all kinds of MIDI software, such as a PatchEditor that wants to save some System Exclusive messages it received from a MIDI module. (The"timestamp" for each message may be irrelevant to such a Patch Editor. But it's easilyignored for PSX]]programs that don't really need it). **** [[FF7/TEX_format| TEX texture In conclusion, any software that saves or loads MIDI data should use SMF format for the PC]]its datafiles. *** ==== MIDI File formats for 3D modelsFormat: Chunks ====**** [[FF7/Kernel/Low_level_libraries#Model_formats_for_PSX|Model Formats for PSX]]**** Model Formats for PC* [[FF7Data is always saved within a <B>chunk</Menu_Module|The Menu Module]]B>. There can be many chunks inside of a MIDI file.** Menu Overview** Menu Initialization** Menu ModulesEach chunk can be a different size (and likely will be). A chunk's size is how many (8-bit)** Calling bytes are contained in the various menuschunk.** Menu dependencies** [[FF7/Savemap|The Save Game format]]data bytes in a chunk are typically related in some way. For example, all of the bytes in one chunk may be for one particular sequencer track. The bytes for another sequencer track may be put in* [[FF7/Field_Module| The Field Module]]a different chunk. So, a chunk is simply a group of related bytes.** Field Overview** Field Format Each chunk must begin with a 4 character (PCie, 4 ascii bytes)<B>ID</B> which tells what "type"of chunk this is.*** General PC Field File Format*** PC Field File HeaderThe next 4 bytes must form a 32-bit length (ie, size) of the chunk.*** File Section Details** [[FF7<U>All chunks must begin with these two fields</Field_Module#Field_Format_.28PSX.29|Field Format U> (PSXie, 8 bytes)]], which are referred to as the*** [[FF7<B>chunk header</Field_Module#PSX_DAT_Format|PSX DAT Format]]B>. Here's what a chunk's header looks like if you defined it in C:<pre>*** [[FF7/Field_Module#PSX_MIM_Format|PSX MIM Format]]struct CHUNK_HEADER*** [[FF7/Field_Module#PSX_BSX_Format|PSX BSX Format]]{*** char ID[[FF7/Field_Module#PSX_BCX_Format|PSX BCX Format]4];* The Battle Module unsigned long Length; ** Battle Overview};** [[FF7</Battlepre><B><FONT COLOR=RED>NOTE:</Battle_Mechanics| Battle Mechanics]]** [[FF7FONT></BattleB> The <B>Length</Battle_Field| Battle Field]]B> does not include the 8 byte chunk** [[FF7header. It simply tells you how many bytes of data are in the chunk <U>following this header</BattleU>. And here's an example chunk header (with bytes expressed in hex) if you examined it with a hex editor: 4D 54 68 64 00 00 00 06 Note that the first 4 bytes make up the ascii ID of <B>MThd</Battle_Scenes| Battle Scenes B> (sceneie, the first fourbytes are the ascii values for 'M', 'T', 'h', and 'd').binThe next 4 bytes tell us that there shouldbe 6 more data bytes in the chunk (and after that we should find the next chunk header or the endof the file)]]. === MIDI File Format: MThd Chunk === *** [[FF7The MThd header has an ID of <B>MThd</BattleB>, and a Length of <B>6</Battle_Scenes/Battle_Script| Battle Scripts]]B>. ** [[FF7/Playstation_Battle_Model_Format| Battle Models Let's examine the 6 data bytes (PSXwhich follow the MThd header)]]in an MThd chunk. ** [[FF7/BattleThe first two data bytes tell the <B>Format</Battle_Animation_B> (PCwhich I prefer to call "type")| Battle Animation .There are actually 3 different types (PCie, formats)]]of MIDI files. A type of 0 means that the filecontains one single track containing midi data on possibly all 16 midi channels. If your sequencer* [[FF7sorts/WorldMap_Module| The World Map Module]]stores all of its midi data in one single block of memory with the data in the order that it's** [[FF7"played", then it should read/World_Map/BSZ| World Map BSZ model write this type. A type of 1 means that the file format contains one ormore simultaneous (ie, all start from an assumed time of 0) tracks, perhaps each on a single midichannel. Together, all of these tracks are considered one sequence or pattern. If yoursequencer separates its midi data (PSXi.e. tracks)]]into different blocks of memory but plays them back** [[FF7simultaneously (ie, as one "pattern"), it will read/World_Mapwrite this type. A type of 2 means that thefile contains one or more sequentially independant single-track patterns. If your sequencerseparates its midi data into different blocks of memory, but plays only one block at a time (ie,each block is considered a different "excerpt" or "song"), then it will read/TXZ| World Map TXZ write this type. The next 2 bytes tell how many tracks are stored in the file , <B>NumTracks</B>. Of course,for format type 0, this is always 1. For the other 2 types, there can be numerous tracks. The last two bytes indicate how many Pulses (PSXi.e. clocks)]]Per Quarter Note (abbreviated as PPQN) resolution the time-stamps are based upon, <B>Division</B>. For example, if your sequencer has 96 ppqn, this field would be (in hex):** [[FF7/WorldMap_Module/Script| World Map Script Engine]]* Sound00 60** [[FF7/PSX/PSX_Sound|PSX Sound]]*** [[FF7<B><FONT COLOR=RED>NOTE:</PSXFONT></SoundB> The 4 bytes that make up the <B>Length</Overview|Overview]]B> are stored in (Motorola) "Big Endian" byte order, not (Intel) "Little Endian" reverse byte order. (ie, The 06 is the fourth byte insteadof the first of the four). *** [[FF7In fact, all MIDI files begin with the above <B>MThd header</PSX/Sound/INSTRxB> (and that's how you know that it'sa MIDI file). Alternately, if the first byte of Division is negative, then this represents the divisionof a second that the time-stamps are based upon. The first byte will be -24, -25, -29, or -30,corresponding to the 4 SMPTE standards representing frames per second.DAT|INSTRxThe second byte (apositive number) is the resolution within a frame (ie, subframe).DAT]]Typical values may be 4 (MIDI*** [[FF7/PSX/Sound/INSTRxTime Code), 8, 10, 80 (SMPTE bit resolution), or 100.ALL|INSTRx You can specify millisecond-based timing by the data bytes of -25 and 40 subframes.ALL]] Here's what an MThd chunk looks like if you defined it in C: <pre>struct MTHD_CHUNK{ /*Here's the 8 byte header that all chunks must have ** / char ID[[FF74]; /PSX* This will be 'M','T','h','d' */Sound unsigned long Length; /AKAO_frames|AKAO frames]]*This will be 6 * PC Sound/ /* Here are the 6 bytes * [[FF7/Technical| Technical Help]]* [[FF7 unsigned short Format; unsigned short NumTracks; unsigned short Division;};</Technical/Customising|Tools and patches]]pre> And here's an example of a complete MThd chunk (with header) if you examined it in a hex editor:<pre>4D 54 68 64 MThd ID00 00 00 06 Length of the MThd chunk is always 6.00 01 The Format type is 1.00 02 There are 2 MTrk chunks in this file.E7 28 Each increment of delta-time represents a millisecond.* [[FF7</Technical/Source|Source Code Forensics]]pre>