MIDICSV(5) | File Formats Manual | MIDICSV(5) |
midicsv - MIDI Comma-Separated Value (CSV) file format
The midicsv and csvmidi programs permit you to intertranslate standard MIDI files and comma-separated value (CSV) files. These CSV files preserve all information in the MIDI file, and may be loaded into spreadsheet and database programs or easily manipulated with text processing tools. This document describes the CSV representation of MIDI files written by midicsv and read by csvmidi. Readers are assumed to understand the structure, terminology, and contents of MIDI files-please refer to a MIDI file reference for details.
Each record in the CSV representation of a MIDI contains at least three fields:
Records in the CSV file are sorted first by the track number, then by time. Out of order records will be discarded with an error message from csvmidi. Following the three required fields are parameter fields which depend upon the Type; some Types take no parameters. Each Type and its parameter fields is discussed below.
Any line with an initial nonblank character of ``#'' or ``;'' is ignored; either delimiter may be used to introduce comments in a CSV file. Only full-line comments are permitted; you cannot use these delimiters to terminate scanning of a regular data record. Completely blank lines are ignored.
The following events occur within MIDI tracks and specify various kinds of information and actions. They may appear at any time within the track. Those which provide general information for which time is not relevant usually appear at the start of the track with Time zero, but this is not a requirement.
Many of these meta-events include a text string argument. Text strings are output in CSV records enclosed in ASCII double quote (") characters. Quote characters embedded within strings are represented by two consecutive quotes. Non-graphic characters in the ISO 8859/1 Latin 1 set are output as a backslash followed by their three digit octal character code. Two consecutive backslashes denote a literal backslash in the string. Strings in MIDI files can be extremely long, theoretically as many as 2**28-1 characters; programs which process MIDI CSV files should take care to avoid buffer overflows or truncation resulting from lines containing long string items. All meta-events which take a text argument are identified by a suffix of ``_t''.
These events are the ``meat and potatoes'' of MIDI files: the actual notes and modifiers that command the instruments to play the music. Each has a MIDI channel number as its first argument, followed by event-specific parameters. To permit programs which process CSV files to easily distinguish them from meta-events, names of channel events all have a suffix of ``_c''.
System Exclusive events permit storing vendor-specific information to be transmitted to that vendor's products.
The following CSV file defines the five-note motif from the film Close Encounters of the Third Kind using an organ patch from the General MIDI instrument set. When processed by midicsv and sent to a synthesiser which conforms to General MIDI, the sequence will be played.
0, 0, Header, 1, 2, 480 1, 0, Start_track 1, 0, Title_t, "Close Encounters" 1, 0, Text_t, "Sample for MIDIcsv Distribution" 1, 0, Copyright_t, "This file is in the public domain" 1, 0, Time_signature, 4, 2, 24, 8 1, 0, Tempo, 500000 1, 0, End_track 2, 0, Start_track 2, 0, Instrument_name_t, "Church Organ" 2, 0, Program_c, 1, 19 2, 0, Note_on_c, 1, 79, 81 2, 960, Note_off_c, 1, 79, 0 2, 960, Note_on_c, 1, 81, 81 2, 1920, Note_off_c, 1, 81, 0 2, 1920, Note_on_c, 1, 77, 81 2, 2880, Note_off_c, 1, 77, 0 2, 2880, Note_on_c, 1, 65, 81 2, 3840, Note_off_c, 1, 65, 0 2, 3840, Note_on_c, 1, 72, 81 2, 4800, Note_off_c, 1, 72, 0 2, 4800, End_track 0, 0, End_of_file
The CSV representation of a MIDI file is simply a text-oriented encoding of its contents. If the input to midicsv contains errors which violate the MIDI standard, the resulting CSV file will faithfully replicate these errors. Similarly, the CSV input to csvmidi must not only consist of records which conform to the syntax given in this document, the input as a whole must also be a semantically correct MIDI file. Programs which wish to use csvmidi to generate MIDI files from scratch should be careful to conform to the structure required of MIDI files. When in doubt, use midicsv to dump a sequence comparable to the one your program will create and use its structure as a template for your own.
Please report errors to bugs@fourmilab.ch.
John Walker
http://www.fourmilab.ch/
This software is in the public domain. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, without any conditions or restrictions. This software is provided ``as is'' without express or implied warranty.
29 MAR 2004 | 4th Berkeley Distribution |