This is midifile.h in view mode; [Download] [Up]
#include <streams/streams.h> /* * The event record that is used to communicate with this midifile module. * If the metaevent flag is set, then see MIDI_METAEVENT_* below */ typedef struct { int quanta; // time (in ticks) unsigned int metaevent:1; // set if the event is a midifile metaevent unsigned int ndata:7; // number of bytes of data unsigned char data[3]; // array of data } midievent_t; /* * Only the two following metaevents are supported; data[0] contains one * of the following codes if the metaevent flag is set. The metaevents are * provided for reading. Separate functions exist to write metaevents. */ #define MIDI_METAEVENT_TEMPO_CHANGE 0 /* * Tempo change metaevent: data[1] and data[2] contain high and low order * bytes, respectively, containing an integer number of beats per minute. */ #define MIDI_METAEVENT_TRACK_CHANGE 1 /* * Track change metaevent: data[1] and data[2] contain high and low order * bytes, respectively, containing the track number. bdw: These events should * only be encountered when reading a level-1 file, but there may be level-0 * files created by the old version of recordmidifile with multiple tracks * (these files are not portable to other software supporting Standard MIDI * Files, but are supported here for backwards compatibility in the NeXT * community). */ int MIDISetQuantaSize(int usec); int MIDIGetQuantaSize(); /* * Set/get the quanta size, specified in microseconds. The default value * is 1000 (one millisecond quanta). All routines for reading and writing * specify time in terms of this size quanta. */ /***************** * * Reading - a typical sequence is: * * if (MIDIFileReadPreamble(myStream,&myLevel,&myTrackcount)) { * (while (MIDIFileReadEvent(myStream,&myEvent)) { * processEvent(&myEvent); * } * } */ int MIDIFileReadPreamble(NXStream *s, int *level, int *track_count); /* * Read the header of the specified file, and return the midifile level * (format) of the file, and the total number of tracks, in the respective * parameters. The return value will be non-zero if all is well; any error * causes zero to be returned. */ int MIDIFileReadEvent(NXStream *s, midievent_t *event); /* * Read the next event in the current track. Return nonzero if successful; * zero if an error or end-of-stream occurred. */ /**************** * * Writing - a typical sequence for a level one file is: * * if (MIDIFileBeginWriting(myStream,1,myTitle)) { * MIDIFileWriteTempo(myStream,myTempo) * for (i=0; i<myTrackCount; i++) { * MIDIFileBeginWritingTrack(myStream,myTrackName[i]); * while (getMyNextEvent(&theEvent)) * MIDIFileWriteEvent(myStream,&theEvent); * MIDIFileEndWritingTrack(myStream); * } * MIDIFileEndWriting(myStream); * } * * Or, for a level zero file: * * if (MIDIFileBeginWriting(myStream,0,myTitle)) { * MIDIFileWriteTempo(myStream,myTempo) * while (getMyNextEvent(&theEvent)) * MIDIFileWriteEvent(myStream,&theEvent); * MIDIFileEndWriting(myStream); * } */ int MIDIFileBeginWriting(NXStream *s, int level, char *sequenceName); /* * Writes the preamble and opens track zero for writing. In level 1 files, * track zero is used by convention for timing information (tempo,time * signature, click track). To begin the first track in this case, first * call MIDIFileBeginWritingTrack. * MIDIFileBeginWriting must be balanced by a call to MIDIFileEndWriting. */ int MIDIFileEndWriting(NXStream *s); /* * Terminates writing to the stream. After this call, the stream may * be closed. */ int MIDIFileBeginWritingTrack(NXStream *s, char *trackName); int MIDIFileEndWritingTrack(NXStream *s); /* * These two functions must be called in a level 1 file to bracket each * chunk of track data (except track 0, which is special). */ int MIDIFileWriteTempo(NXStream *s, int beats_per_minute); /* * Writes the 'set tempo' metaevent to the stream. This may be just after * a call to MIDIFileBeginWriting, in which it goes into the special track * zero, or it may be called within any track. By convention, however, tempo * changes should go in track zero. */ int MIDIFileWriteEvent(NXStream *s, midievent_t *event); /* * Writes the arbitrary event to stream. Returns zero if it fails. */
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.