JNIEXPORT jstring JNICALL Java_com_sun_media_sound_HeadspaceSoundbank_nGetName(JNIEnv* e, jobject thisObj, jlong id) { XFILE oldResourceFile = NULL; XFILE thisResourceFile = NULL; BankStatus bank; char name[BANK_NAME_MAX_SIZE]; name[0] = 0; oldResourceFile = XFileGetCurrentResourceFile(); thisResourceFile = (XFILE) (INT_PTR) id; if (thisResourceFile) { XFileUseThisResourceFile(thisResourceFile); XGetBankStatus(&bank); if ((UINT32)XStrLen(bank.bankName) == 0) { XFileUseThisResourceFile(oldResourceFile); return NULL; } else { XStrCpy(name, bank.bankName); XFileUseThisResourceFile(oldResourceFile); return (*e)->NewStringUTF(e, name); } } return NULL; }
JNIEXPORT jint JNICALL Java_com_sun_media_sound_HeadspaceSoundbank_nGetVersionSubMinor(JNIEnv* e, jobject thisObj, jlong id) { XFILE oldResourceFile = NULL; XFILE thisResourceFile = NULL; XVersion vers; short int versionSubMinor = 0; oldResourceFile = XFileGetCurrentResourceFile(); thisResourceFile = (XFILE) (INT_PTR) id; if (thisResourceFile) { XFileUseThisResourceFile(thisResourceFile); XGetVersionNumber(&vers); versionSubMinor = vers.versionSubMinor; XFileUseThisResourceFile(oldResourceFile); } return (jint)versionSubMinor; }
XERR XCopyInstrumentResources(XShortResourceID *pInstCopy, short int instCount, XFILE readFileRef, XFILE writeFileRef, XBOOL copyNames) { short int count; XPTR pData; short int theID; long size; char theName[256]; if (instCount && pInstCopy) { XFileUseThisResourceFile(readFileRef); /* from resource file */ for (count = 0; count < instCount; count++) { theID = pInstCopy[count]; XFileUseThisResourceFile(writeFileRef); pData = XGetFileResource(writeFileRef, ID_INST, theID, theName, &size); if (pData == NULL) // check to see that its not there already!! { XFileUseThisResourceFile(readFileRef); /* from resource file */ pData = XGetFileResource(readFileRef, ID_INST, theID, theName, &size); if (pData) { XFileUseThisResourceFile(writeFileRef); if (copyNames == FALSE) { theName[0] = 0; } XAddResource(ID_INST, theID, theName, pData, size); } } XDisposePtr(pData); } } return 0; }
XERR XCopySndResources(XShortResourceID *pSndCopy, short int sndCount, XFILE readFileRef, XFILE writeFileRef, XBOOL protect, XBOOL copyNames) { short int count, resCount; XPTR pData; short int theID; char theName[256]; long size; long soundTypes[] = {ID_SND, ID_ESND, ID_CSND}; if (sndCount && pSndCopy) { XFileUseThisResourceFile(readFileRef); /* from resource file */ for (count = 0; count < sndCount; count++) { theID = pSndCopy[count]; // determine if the resource is already in the written file XFileUseThisResourceFile(writeFileRef); pData = XGetAndDetachResource(ID_SND, theID, &size); if (pData == NULL) { pData = XGetAndDetachResource(ID_ESND, theID, &size); } if (pData == NULL) { pData = XGetAndDetachResource(ID_CSND, theID, &size); } XDisposePtr(pData); if (pData == NULL) // check to see that its not there already!! { for (resCount = 0; resCount < 3; resCount++) { XFileUseThisResourceFile(readFileRef); /* from resource file */ pData = XGetFileResource(readFileRef, soundTypes[resCount], theID, theName, &size); if (pData) { if (copyNames == FALSE) { theName[0] = 0; } XFileUseThisResourceFile(writeFileRef); if (protect && (soundTypes[resCount] == ID_SND)) { XEncryptData(pData, size); XAddResource(ID_ESND, theID, theName, pData, size); } else { XAddResource(soundTypes[resCount], theID, theName, pData, size); } XDisposePtr(pData); } } } else { XDisposePtr(pData); } } } return 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; }