[AD] .RMI midi file support. |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
/* ______ ___ ___ * /\ _ \ /\_ \ /\_ \ * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ * \/_/\/_/\/____/\/____/\/____/\/___L\ \/_/ \/___/ * /\____/ * \_/__/ * * The core MIDI file player. * * By Shawn Hargreaves. * * load_rmi function by Ron S. Novy (cut & paste from load_midi ;) * * See readme.txt for copyright information. */ #include <string.h> #include "allegro.h" #include "allegro/internal/aintern.h" /* load_midi: * Loads a standard MIDI file, returning a pointer to a MIDI structure, * or NULL on error. */ MIDI *load_rmi(AL_CONST char *filename) { int c; char buf[4]; long data; PACKFILE *fp; MIDI *midi; int num_tracks; ASSERT(filename); fp = pack_fopen(filename, F_READ); /* open the file */ if (!fp) return NULL; midi = malloc(sizeof(MIDI)); /* get some memory */ if (!midi) { pack_fclose(fp); return NULL; } for (c=0; c<MIDI_TRACKS; c++) { midi->track[c].data = NULL; midi->track[c].len = 0; } pack_fread(buf, 4, fp); if (memcmp(buf, "RIFF", 4)) /* check for RIFF */ goto err; pack_mgetl(fp); /* skip RIFF chunk length */ pack_fread(buf, 4, fp); if (memcmp(buf, "RMID", 4)) /* check for chunk type RMID */ goto err; pack_fread(buf, 4, fp); if (memcmp(buf, "data", 4)) /* check for data chunk */ goto err; pack_mgetl(fp); /* skip data chunk length */ pack_fread(buf, 4, fp); /* read midi header */ if (memcmp(buf, "MThd", 4)) goto err; pack_mgetl(fp); /* skip header chunk length */ data = pack_mgetw(fp); /* MIDI file type */ if ((data != 0) && (data != 1)) goto err; num_tracks = pack_mgetw(fp); /* number of tracks */ if ((num_tracks < 1) || (num_tracks > MIDI_TRACKS)) goto err; data = pack_mgetw(fp); /* beat divisions */ midi->divisions = ABS(data); for (c=0; c<num_tracks; c++) { /* read each track */ pack_fread(buf, 4, fp); /* read track header */ if (memcmp(buf, "MTrk", 4)) goto err; data = pack_mgetl(fp); /* length of track chunk */ midi->track[c].len = data; midi->track[c].data = malloc(data); /* allocate memory */ if (!midi->track[c].data) goto err; /* finally, read track data */ if (pack_fread(midi->track[c].data, data, fp) != data) goto err; } pack_fclose(fp); lock_midi(midi); return midi; /* oh dear... */ err: pack_fclose(fp); destroy_midi(midi); return NULL; }
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |