// This will return a MIDI/CMID/EMID/ECMI object from an open resource file // // INPUT: // theXSong is the SongResource structure // // OUTPUT: // pMusicName is a pascal string // pMusicType is the resource type // pMusicID is the resource ID // pReturnedSize is the resource size XPTR XGetMusicObjectFromSong(SongResource *theXSong, char *pMusicName, XResourceType *pMusicType, XLongResourceID *pMusicID, long *pReturnedSize) { long musicID; SongType songType; XPTR data; XResourceType midiTypes[] = {ID_MIDI, ID_MIDI_OLD, ID_CMID, ID_EMID, ID_ECMI}; short int count; data = NULL; if (pReturnedSize) { *pReturnedSize = 0; } if (pMusicName) { pMusicName[0] = 0; } if (theXSong) { *pMusicType = 0; *pMusicID = 0; musicID = XGetSongResourceObjectID(theXSong); songType = XGetSongResourceObjectType(theXSong); for (count = 0; count < (sizeof(midiTypes) / sizeof(long)); count++) { data = XGetAndDetachResource(midiTypes[count], musicID, pReturnedSize); if (data) { if (pMusicName) { XGetResourceName(midiTypes[count], musicID, pMusicName); XCtoPstr(pMusicName); } *pMusicType = midiTypes[count]; *pMusicID = musicID; break; } } } return data; }
GM_Song * GM_LoadSong(void *threadContext, void *context, XShortResourceID songID, void *theExternalSong, void *theExternalMidiData, INT32 midiSize, XShortResourceID *pInstrumentArray, XBOOL loadInstruments, XBOOL ignoreBadInstruments, OPErr *pErr) { GM_Song *pSong; XLongResourceID songObjectID; *pErr = MEMORY_ERR; pSong = NULL; if (theExternalSong) { songObjectID = (XLongResourceID)XGetSongResourceObjectID(theExternalSong); switch (XGetSongResourceObjectType(theExternalSong)) { case SONG_TYPE_SMS: pSong = PV_CreateSongFromMidi(songObjectID, theExternalMidiData, midiSize); break; case SONG_TYPE_RMF: if (theExternalMidiData == NULL) { // we only support midi data via the resource manager pSong = PV_CreateSongFromMidi(songObjectID, NULL, 0); } else { *pErr = PARAM_ERR; } break; case SONG_TYPE_BAD: case SONG_TYPE_RMF_LINEAR: /* satisfy compiler */ break; } } // load instruments if (pSong) { pSong->pSynths = NULL; pSong->context = context; GM_MergeExternalSong(theExternalSong, songID, pSong); pSong->ignoreBadInstruments = ignoreBadInstruments; *pErr = GM_LoadSongInstruments(pSong, pInstrumentArray, loadInstruments); if (*pErr) { GM_FreeSong(threadContext, pSong); // we ignore the error codes, because it should be ok to dispose pSong = NULL; } else { // song length not calculated pSong->songMidiTickLength = 0; pSong->songMicrosecondLength = 0; *pErr = NO_ERR; } } return pSong; }