예제 #1
0
static GM_Song * PV_CreateSongFromMidi(XLongResourceID theID, XPTR useThisMidiData, INT32 midiSize)
{
    XPTR		theMidiData;
    GM_Song		*theSong;
    INT32		count;

    theSong = NULL;
    if (useThisMidiData)
	{
	    theMidiData = useThisMidiData;
	}
    else
	{
	    midiSize = 0;
	    theMidiData = XGetMidiData(theID, &midiSize, NULL);
	}
    if (theMidiData)
	{
	    theSong = (GM_Song *)XNewPtr((INT32)sizeof(GM_Song));
	    if (theSong)
		{
		    theSong->midiData = theMidiData;
		    theSong->midiSize = midiSize;
		    theSong->disposeSongDataWhenDone = (useThisMidiData == NULL) ? TRUE : FALSE;
		    // Fill in remap first
		    for (count = 0; count < (MAX_INSTRUMENTS*MAX_BANKS); count++)
			{
			    theSong->instrumentRemap[count] = (XLongResourceID)-1;		// no remap
			}
		}
	}
    return theSong;
}
예제 #2
0
XERR XCopySongMidiResources(XLongResourceID theSongID, XFILE readFileRef, 
			    XFILE writeFileRef, XBOOL protect, XBOOL copyNames)
{
    XPTR			pData;
    SongResource	*theSong;
    long			songSize;
    XResourceType	theDataType;
    short int		theID;
    char			theName[256], theSongName[256];
    unsigned long	dataSize, newSize;
    XPTR			newMidiData;

    XFileUseThisResourceFile(readFileRef);		// from resource file
    theSong = (SongResource *)XGetFileResource(readFileRef, ID_SONG, theSongID, theSongName, &songSize);
    if (theSong)
	{
	    theID = XGetSongResourceObjectID(theSong);

	    if (protect)
		{
		    pData = XGetMidiData(theID, (long *)&dataSize, &theDataType);
		    if (pData)
			{
			    newMidiData = XCompressAndEncrypt(pData, dataSize, &newSize);
			    if (newMidiData)
				{
				    theDataType = ID_ECMI;
				    XDisposePtr(pData);
				    pData = newMidiData;
				}
			    else
				{
				    theDataType = ID_MIDI;
				}
			}
		}
	    else
		{
		    theDataType = ID_CMID;
		    pData = XGetFileResource(readFileRef, ID_CMID, theID, theName, (long *)&dataSize);
		    if (pData == NULL)
			{
			    theDataType = ID_ECMI;
			    pData = XGetFileResource(readFileRef, ID_ECMI, theID, theName, (long *)&dataSize);
			}
		    if (pData == NULL)
			{
			    theDataType = ID_EMID;
			    pData = XGetFileResource(readFileRef, ID_EMID, theID, theName, (long *)&dataSize);
			}
		    if (pData == NULL)
			{
			    theDataType = ID_MIDI;
			    pData = XGetFileResource(readFileRef, ID_MIDI, theID, theName, (long *)&dataSize);
			}
		    if (pData == NULL)
			{
			    theDataType = ID_MIDI;		// convert it to the new type
			    pData = XGetFileResource(readFileRef, ID_MIDI_OLD, theID, theName, (long *)&dataSize);
			}
		}
	    if (pData)
		{
		    // write midi resource
		    XFileUseThisResourceFile(writeFileRef);
		    if (copyNames == FALSE)
			{
			    theName[0] = 0;
			}
		    XAddResource(theDataType, theID, theName, pData, (long)dataSize);
		    XDisposePtr(pData);

		    // write song resource
		    XFileUseThisResourceFile(readFileRef);

		    if (protect)
			{
			    XSetSongLocked(theSong, TRUE);
			}

		    XFileUseThisResourceFile(writeFileRef);
		    XAddResource(ID_SONG, theID, theName, theSong, songSize);
		    XDisposePtr(theSong);
		}
	}
    return 0;
}