// GetSettingsPreference // Returns a preference for a specified key as QuickTime UserData // It is your responsibility to dispose of the returned UserData OSErr GetSettingsPreference(CFStringRef inKey, UserData *outUserData) { CFPropertyListRef theCFSettings; Handle theHandle = NULL; UserData theUserData = NULL; OSErr err = paramErr; // read the new setttings from our preferences theCFSettings = CFPreferencesCopyAppValue(inKey, kCFPreferencesCurrentApplication); if (theCFSettings) { err = PtrToHand(CFDataGetBytePtr((CFDataRef)theCFSettings), &theHandle, CFDataGetLength((CFDataRef)theCFSettings)); CFRelease(theCFSettings); if (theHandle) { err = NewUserDataFromHandle(theHandle, &theUserData); if (theUserData) { *outUserData = theUserData; } DisposeHandle(theHandle); } } return err; }
void write_setting_i(void *handle, char const *key, int value) { int fd = *(int *)handle; Handle h; int id; OSErr error; Str255 pkey; UseResFile(fd); if (ResError() != noErr) fatalbox("Failed to open saved session (%d)", ResError()); /* XXX assume all systems have the same "int" format */ error = PtrToHand(&value, &h, sizeof(int)); if (error != noErr) fatalbox("Failed to allocate memory (%d)", error); /* Put the data in a resource. */ id = Unique1ID(FOUR_CHAR_CODE('Int ')); if (ResError() != noErr) fatalbox("Failed to get ID for resource %s (%d)", key, ResError()); c2pstrcpy(pkey, key); AddResource(h, FOUR_CHAR_CODE('Int '), id, pkey); if (ResError() != noErr) fatalbox("Failed to add resource %s (%d)", key, ResError()); }
static pascal OSErr CoercePSNToType (DescType typecode, Ptr dataptr, Size datasize, DescType totype, long refcon, AEDesc *result) { #pragma unused (typecode, datasize, totype, refcon) ProcessInfoRec info; OSErr ec; info.processInfoLength = (long) sizeof (info); info.processName = nil; info.processAppSpec = nil; //Code check by Timothy Paustian Tuesday, April 25, 2000 10:22:33 PM //somewhat of a dangerous call, This routine assumed the dataptr coming in //is a ProcessSerialNumber, only accesses the signature so OK. ec = GetProcessInformation ((ProcessSerialNumber *) dataptr, &info); if (ec != noErr) return (ec); (*result).descriptorType = typeType; #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/ return (putdescdatapointer (result, typeType, &info.processSignature, 4)); #else return (PtrToHand (&info.processSignature, &(*result).dataHandle, 4)); #endif } /*CoercePSNToType*/
static PGPError sImportProc( PFLFileSpecRef ref, PGPByte const * data, PGPSize dataSize ) { const ExportedFileSpec * exportedData; MyData * newData = NULL; PGPError err = kPGPError_NoErr; (void) dataSize; exportedData = (const ExportedFileSpec *)data; newData = GetMyData( ref ); err = PGPReallocData( ref->memoryMgr, &newData, sizeof( *newData ), 0 ); if ( IsntPGPError( err ) ) { MyData * myData = (MyData *)newData; ref->data = (PGPByte *)newData; ref->dataSize = sizeof( *newData ); myData->specIsValid = FALSE; CopyPString( exportedData->name, myData->spec.name ); if( exportedData->aliasDataSize != 0 ) { AliasHandle alias; if( PtrToHand( &exportedData->aliasData[0], (Handle *) &alias, exportedData->aliasDataSize ) == noErr ) { FSSpec spec; short aliasCount = 1; Boolean needsUpdate; if( MatchAlias( NULL, kARMNoUI | kARMSearch, alias, &aliasCount, &spec, &needsUpdate, NULL, NULL ) == noErr ) { CInfoPBRec cpb; if( FSpGetCatInfo( &spec, &cpb ) == noErr ) { myData->specIsValid = TRUE; myData->spec.vRefNum = spec.vRefNum; myData->spec.parID = cpb.dirInfo.ioDrDirID; } } DisposeHandle( (Handle) alias ); } } } return( err ); }
static pascal ComponentResult myDataHGetFileTypeOrdering ( DataHandler dh, DataHFileTypeOrderingHandle *orderingListHandle) { OSType orderlist[1] = {kDataHFileTypeExtension}; TRACE("\n"); PtrToHand( &orderlist, (Handle*)orderingListHandle, sizeof(OSType)); return noErr; }
Handle MacCreateDataReferenceHandle(Handle theDataHandle) { Handle dataRef = NULL; OSErr err = noErr; // Create a data reference handle for our data. err = PtrToHand( &theDataHandle, &dataRef, sizeof(Handle)); return dataRef; }
OSErr QTUtils_SetMovieTargetID (Movie theMovie, long theTargetID) { UserData myUserData = NULL; long myID = 0; char *myString = NULL; Str255 myPString; char *myCString = NULL; Handle myHandle = NULL; OSErr myErr = noErr; // make sure we've got a movie if (theMovie == NULL) return(paramErr); // get the movie's user data list myUserData = GetMovieUserData(theMovie); if (myUserData == NULL) return(paramErr); // remove any existing movie target ID while (QTUtils_FindUserDataItemWithPrefix(myUserData, FOUR_CHAR_CODE('plug'), kMovieIDPrefix) != 0) RemoveUserData(myUserData, FOUR_CHAR_CODE('plug'), QTUtils_FindUserDataItemWithPrefix(myUserData, FOUR_CHAR_CODE('plug'), kMovieIDPrefix)); // convert the ID into a string NumToString(theTargetID, myPString); myCString = QTUtils_ConvertPascalToCString(myPString); if (myCString == NULL) return(paramErr); // create the user data item data myString = malloc(strlen(kMovieIDPrefix) + strlen(myCString) + 2 + 1); // 2 + 1 == '\"' + '\"' + '\0' if (myString != NULL) { myString[0] = '\0'; strcat(myString, kMovieIDPrefix); strcat(myString, "\""); strcat(myString, myCString); strcat(myString, "\""); // add in a new user data item PtrToHand(myString, &myHandle, strlen(myString)); if (myHandle != NULL) myErr = AddUserData(myUserData, myHandle, FOUR_CHAR_CODE('plug')); } else { myErr = memFullErr; } free(myString); free(myCString); if (myHandle != NULL) DisposeHandle(myHandle); return(myErr); }
Handle getPtrDataRef(unsigned char *data, unsigned int size, const std::string &filename) { // Load Data Reference Handle dataRef; Handle fileNameHandle; PointerDataRefRecord ptrDataRefRec; ComponentInstance dataRefHandler; unsigned char pstr[255]; ptrDataRefRec.data = data; ptrDataRefRec.dataLength = size; /*err = */PtrToHand(&ptrDataRefRec, &dataRef, sizeof(PointerDataRefRecord)); // Open a Data Handler for the Data Reference /*err = */OpenADataHandler(dataRef, PointerDataHandlerSubType, NULL, (OSType)0, NULL, kDataHCanRead, &dataRefHandler); // Convert From CString in filename to a PascalString in pstr if (filename.length() > 255) { //hmm...not good, pascal string limit is 255! //do some error handling maybe?! throw QTImportExportException(0, "filename length limit exceeded"); } CopyCStringToPascal(filename.c_str(), pstr); // Add filename extension /*err = */PtrToHand(pstr, &fileNameHandle, filename.length() + 1); /*err = */DataHSetDataRefExtension(dataRefHandler, fileNameHandle, kDataRefExtensionFileName); DisposeHandle(fileNameHandle); // Release old handler which does not have the extensions DisposeHandle(dataRef); // Grab the SAFE_NEW version of the data ref from the data handler /*err = */ DataHGetDataRef(dataRefHandler, &dataRef); CloseComponent(dataRefHandler); return dataRef; }
static pascal ComponentResult myComponentOpen(ComponentInstance ci, ComponentInstance self) { DHData myData; Handle storage; ZeroMemory(&myData,sizeof(DHData)); PtrToHand( &myData, &storage, sizeof(DHData)); SetComponentInstanceStorage(self,storage); return noErr; }
static OSErr QT_GetCodecSettingsFromScene(RenderData *rd, ReportList *reports) { Handle myHandle = NULL; ComponentResult myErr = noErr; QuicktimeCodecData *qcd = rd->qtcodecdata; /* if there is codecdata in the blendfile, convert it to a Quicktime handle */ if (qcd) { myHandle = NewHandle(qcd->cdSize); PtrToHand(qcd->cdParms, &myHandle, qcd->cdSize); } /* restore codecsettings to the quicktime component */ if (qcd->cdParms && qcd->cdSize) { myErr = SCSetSettingsFromAtomContainer((GraphicsExportComponent)qtdata->theComponent, (QTAtomContainer)myHandle); if (myErr != noErr) { BKE_report(reports, RPT_ERROR, "Quicktime: SCSetSettingsFromAtomContainer failed"); goto bail; } /* update runtime codecsettings for use with the codec dialog */ SCGetInfo(qtdata->theComponent, scDataRateSettingsType, &qtdata->aDataRateSetting); SCGetInfo(qtdata->theComponent, scSpatialSettingsType, &qtdata->gSpatialSettings); SCGetInfo(qtdata->theComponent, scTemporalSettingsType, &qtdata->gTemporalSettings); /* Fill the render QuicktimeCodecSettigns struct */ rd->qtcodecsettings.codecTemporalQuality = (qtdata->gTemporalSettings.temporalQuality * 100) / codecLosslessQuality; /* Do not override scene frame rate (qtdata->gTemporalSettings.framerate) */ rd->qtcodecsettings.keyFrameRate = qtdata->gTemporalSettings.keyFrameRate; rd->qtcodecsettings.codecType = qtdata->gSpatialSettings.codecType; rd->qtcodecsettings.codec = (int)qtdata->gSpatialSettings.codec; rd->qtcodecsettings.colorDepth = qtdata->gSpatialSettings.depth; rd->qtcodecsettings.codecSpatialQuality = (qtdata->gSpatialSettings.spatialQuality * 100) / codecLosslessQuality; rd->qtcodecsettings.bitRate = qtdata->aDataRateSetting.dataRate; rd->qtcodecsettings.minSpatialQuality = (qtdata->aDataRateSetting.minSpatialQuality * 100) / codecLosslessQuality; rd->qtcodecsettings.minTemporalQuality = (qtdata->aDataRateSetting.minTemporalQuality * 100) / codecLosslessQuality; /* Frame duration is already known (qtdata->aDataRateSetting.frameDuration) */ } else { BKE_report(reports, RPT_ERROR, "Quicktime: QT_GetCodecSettingsFromScene failed"); } bail: if (myHandle != NULL) DisposeHandle(myHandle); return((OSErr)myErr); }
OSErr QTUtils_SetMovieTargetName (Movie theMovie, char *theTargetName) { UserData myUserData = NULL; char *myString = NULL; Handle myHandle = NULL; OSErr myErr = noErr; // make sure we've got a movie and a name if ((theMovie == NULL) || (theTargetName == NULL)) return(paramErr); // get the movie's user data list myUserData = GetMovieUserData(theMovie); if (myUserData == NULL) return(paramErr); // remove any existing movie target name while (QTUtils_FindUserDataItemWithPrefix(myUserData, FOUR_CHAR_CODE('plug'), kMovieNamePrefix) != 0) RemoveUserData(myUserData, FOUR_CHAR_CODE('plug'), QTUtils_FindUserDataItemWithPrefix(myUserData, FOUR_CHAR_CODE('plug'), kMovieNamePrefix)); // create the user data item data myString = malloc(strlen(kMovieNamePrefix) + strlen(theTargetName) + 2 + 1); // 2 + 1 == '\"' + '\"' + '\0' if (myString != NULL) { myString[0] = '\0'; strcat(myString, kMovieNamePrefix); strcat(myString, "\""); strcat(myString, theTargetName); strcat(myString, "\""); // add in a new user data item PtrToHand(myString, &myHandle, strlen(myString)); if (myHandle != NULL) myErr = AddUserData(myUserData, myHandle, FOUR_CHAR_CODE('plug')); } else { myErr = memFullErr; } free(myString); if (myHandle != NULL) DisposeHandle(myHandle); return(myErr); }
void add_finishing_touches_to_save_file(FileSpecifier &File) // FileDesc *file) { short refnum; unsigned char name[64+1]; OSErr err; FSSpec *SpecPtr = &File.GetSpec(); FInfo finder_info; err = FSpGetFInfo((FSSpec *)SpecPtr, &finder_info); if (err != noErr) return; FSpCreateResFile(SpecPtr, finder_info.fdCreator, finder_info.fdType, smSystemScript); if (ResError() != noErr) return; /* Save the STR resource that tells us what our application name is. */ refnum= FSpOpenResFile(&File.GetSpec(), fsWrPerm); // resource_file_ref= FSpOpenResFile((FSSpec *) file, fsWrPerm); if (refnum < 0) return; Handle resource; /* Add in the overhead thumbnail. */ add_overhead_thumbnail(File); /* Add the application name resource.. */ getpstr(name, strFILENAMES, filenameMARATHON_NAME); // add_application_name_to_fsspec((FileDesc *) file, name); // LP: copied out of files_macintosh.c -- add_application_name_to_fsspec(); // this is the only place that uses this code /* Add in the application name */ err= PtrToHand(name, &resource, name[0]+1); assert(!err && resource); AddResource(resource, 'STR ', -16396, "\p"); ReleaseResource(resource); CloseResFile(refnum); // End copying }
static HRESULT WINAPI IcnsFrameEncode_Commit(IWICBitmapFrameEncode *iface) { IcnsFrameEncode *This = impl_from_IWICBitmapFrameEncode(iface); Handle handle; OSErr ret; HRESULT hr = S_OK; TRACE("(%p)\n", iface); EnterCriticalSection(&This->encoder->lock); if (!This->icns_image || This->lines_written != This->size || This->committed) { hr = WINCODEC_ERR_WRONGSTATE; goto end; } ret = PtrToHand(This->icns_image, &handle, This->size * This->size * 4); if (ret != noErr || !handle) { WARN("PtrToHand failed with error %d\n", ret); hr = E_FAIL; goto end; } ret = SetIconFamilyData(This->encoder->icns_family, This->icns_type, handle); DisposeHandle(handle); if (ret != noErr) { WARN("SetIconFamilyData failed for image with error %d\n", ret); hr = E_FAIL; goto end; } This->committed = TRUE; This->encoder->any_frame_committed = TRUE; This->encoder->outstanding_commits--; end: LeaveCriticalSection(&This->encoder->lock); return hr; }
void write_setting_s(void *handle, char const *key, char const *value) { int fd = *(int *)handle; Handle h; int id; OSErr error; Str255 pkey; UseResFile(fd); if (ResError() != noErr) fatalbox("Failed to open saved session (%d)", ResError()); error = PtrToHand(value, &h, strlen(value)); if (error != noErr) fatalbox("Failed to allocate memory"); /* Put the data in a resource. */ id = Unique1ID(FOUR_CHAR_CODE('TEXT')); if (ResError() != noErr) fatalbox("Failed to get ID for resource %s (%d)", key, ResError()); c2pstrcpy(pkey, key); AddResource(h, FOUR_CHAR_CODE('TEXT'), id, pkey); if (ResError() != noErr) fatalbox("Failed to add resource %s (%d)", key, ResError()); }
OSErr CreateToolNameRes(StringPtr toolName) { short ref; FSSpec prefs; OSErr error; Handle theStrings; // build the 'STR ' resource error = FindPrefs(&prefs); if (error == noErr) { ref = FSpOpenResFile(&prefs, fsRdWrPerm); if (ref != -1) { theStrings = Get1Resource('STR ',kToolNameRes); if (theStrings != nil) { RemoveResource(theStrings); error = ResError(); } error = PtrToHand(toolName, &theStrings, toolName[0] + 1); AddResource(theStrings, 'STR ', kToolNameRes, "\ptoolName"); error = ResError(); ChangedResource(theStrings); error = ResError(); WriteResource(theStrings); error = ResError(); //ReleaseResource(theStrings); // Release the resource from memory. //error = ResError(); UpdateResFile(ref); // No screwing around; write that resource! error = ResError(); FlushVol(nil, prefs.vRefNum); CloseResFile(ref); } else {
boolean filegetdiskicon (short vnum, Handle *hdiskicon) { HParamBlockRec pb; ParamBlockRec cpb; OSErr ec; clearbytes (&pb, longsizeof (pb)); pb.volumeParam.ioVRefNum = vnum; ec = PBHGetVInfoSync (&pb); if (fileerror (nil, ec)) return (false); cpb.cntrlParam.ioCRefNum = pb.volumeParam.ioVDRefNum; cpb.cntrlParam.ioVRefNum = pb.volumeParam.ioVDrvInfo; cpb.cntrlParam.csCode = 22; ec = PBControlSync (&cpb); if (ec != noErr) { cpb.cntrlParam.csCode = 21; ec = PBControlSync (&cpb); } if (fileerror (nil, ec)) return (false); ec = PtrToHand (*(Ptr*) &cpb.cntrlParam.csParam, hdiskicon, kLargeIconSize); return (!fileerror (nil, ec)); } /*filegetdiskicon*/
pascal OSErr FSpGetFullPath(const FSSpec *spec, short *fullPathLength, Handle *fullPath) { OSErr result; OSErr realResult; FSSpec tempSpec; CInfoPBRec pb; *fullPathLength = 0; *fullPath = NULL; // Default to noErr realResult = noErr; /* Make a copy of the input FSSpec that can be modified */ BlockMoveData(spec, &tempSpec, sizeof(FSSpec)); if ( tempSpec.parID == fsRtParID ) { /* The object is a volume */ /* Add a colon to make it a full pathname */ ++tempSpec.name[0]; tempSpec.name[tempSpec.name[0]] = ':'; /* We are done */ result = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]); } else { /* The object is NOT a volume */ /* Is the object a file or a directory? */ pb.dirInfo.ioNamePtr = tempSpec.name; pb.dirInfo.ioVRefNum = tempSpec.vRefNum; pb.dirInfo.ioDrDirID = tempSpec.parID; pb.dirInfo.ioFDirIndex = 0; result = PBGetCatInfoSync(&pb); /* Allow file/directory name at end of path to not exist. */ realResult = result; if ( (result == noErr) || (result == fnfErr) ) { /* if the object is a directory, append a colon so full pathname ends with colon */ if ( (result == noErr) && (pb.hFileInfo.ioFlAttrib & ioDirMask) != 0 ) { ++tempSpec.name[0]; tempSpec.name[tempSpec.name[0]] = ':'; } /* Put the object name in first */ result = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]); if ( result == noErr ) { /* Get the ancestor directory names */ pb.dirInfo.ioNamePtr = tempSpec.name; pb.dirInfo.ioVRefNum = tempSpec.vRefNum; pb.dirInfo.ioDrParID = tempSpec.parID; do /* loop until we have an error or find the root directory */ { pb.dirInfo.ioFDirIndex = -1; pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID; result = PBGetCatInfoSync(&pb); if ( result == noErr ) { /* Append colon to directory name */ ++tempSpec.name[0]; tempSpec.name[tempSpec.name[0]] = ':'; /* Add directory name to beginning of fullPath */ (void) Munger(*fullPath, 0, NULL, 0, &tempSpec.name[1], tempSpec.name[0]); result = MemError(); } } while ( (result == noErr) && (pb.dirInfo.ioDrDirID != fsRtDirID) ); } } } if ( result == noErr ) { /* Return the length */ *fullPathLength = InlineGetHandleSize(*fullPath); result = realResult; // return realResult in case it was fnfErr } else { /* Dispose of the handle and return NULL and zero length */ if ( *fullPath != NULL ) { DisposeHandle(*fullPath); } *fullPath = NULL; *fullPathLength = 0; } return ( result ); }
OSErr FSpPathFromLocation( FSSpec *spec, /* The location we want a path for. */ int *length, /* Length of the resulting path. */ Handle *fullPath) /* Handle to path. */ { OSErr err; FSSpec tempSpec; CInfoPBRec pb; *fullPath = NULL; /* * Make a copy of the input FSSpec that can be modified. */ BlockMoveData(spec, &tempSpec, sizeof(FSSpec)); if (tempSpec.parID == fsRtParID) { /* * The object is a volume. Add a colon to make it a full * pathname. Allocate a handle for it and we are done. */ tempSpec.name[0] += 2; tempSpec.name[tempSpec.name[0] - 1] = ':'; tempSpec.name[tempSpec.name[0]] = '\0'; err = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]); } else { /* * The object isn't a volume. Is the object a file or a directory? */ pb.dirInfo.ioNamePtr = tempSpec.name; pb.dirInfo.ioVRefNum = tempSpec.vRefNum; pb.dirInfo.ioDrDirID = tempSpec.parID; pb.dirInfo.ioFDirIndex = 0; err = PBGetCatInfoSync(&pb); if ((err == noErr) || (err == fnfErr)) { /* * If the file doesn't currently exist we start over. If the * directory exists everything will work just fine. Otherwise we * will just fail later. If the object is a directory, append a * colon so full pathname ends with colon, but only if the name is * not empty. NavServices returns FSSpec's with the parent ID set, * but the name empty... */ if (err == fnfErr) { BlockMoveData(spec, &tempSpec, sizeof(FSSpec)); } else if ( (pb.hFileInfo.ioFlAttrib & ioDirMask) != 0 ) { if (tempSpec.name[0] > 0) { tempSpec.name[0] += 1; tempSpec.name[tempSpec.name[0]] = ':'; } } /* * Create a new Handle for the object - make it a C string. */ tempSpec.name[0] += 1; tempSpec.name[tempSpec.name[0]] = '\0'; err = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]); if (err == noErr) { /* * Get the ancestor directory names - loop until we have an * error or find the root directory. */ pb.dirInfo.ioNamePtr = tempSpec.name; pb.dirInfo.ioVRefNum = tempSpec.vRefNum; pb.dirInfo.ioDrParID = tempSpec.parID; do { pb.dirInfo.ioFDirIndex = -1; pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID; err = PBGetCatInfoSync(&pb); if (err == noErr) { /* * Append colon to directory name and add * directory name to beginning of fullPath. */ ++tempSpec.name[0]; tempSpec.name[tempSpec.name[0]] = ':'; (void) Munger(*fullPath, 0, NULL, 0, &tempSpec.name[1], tempSpec.name[0]); err = MemError(); } } while ( (err == noErr) && (pb.dirInfo.ioDrDirID != fsRtDirID) ); } } } /* * On error Dispose the handle, set it to NULL & return the err. * Otherwise, set the length & return. */ if (err == noErr) { *length = GetHandleSize(*fullPath) - 1; } else { if ( *fullPath != NULL ) { DisposeHandle(*fullPath); } *fullPath = NULL; *length = 0; } return err; }
static OSErr FSpGetFullPath(const FSSpec *spec, short *fullPathLength, Handle *fullPath) { OSErr result; OSErr realResult; FSSpec tempSpec; CInfoPBRec pb; *fullPathLength = 0; *fullPath = nil; /* Default to noErr */ realResult = result = noErr; result = FSMakeFSSpecCompat(spec->vRefNum, spec->parID, spec->name, &tempSpec); if ( result == noErr ) { if ( tempSpec.parID == fsRtParID ) { /* The object is a volume */ /* Add a colon to make it a full pathname */ ++tempSpec.name[0]; tempSpec.name[tempSpec.name[0]] = ':'; /* We're done */ result = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]); *fullPathLength = tempSpec.name[0]; } else { /* The object isn't a volume */ /* Is the object a file or a directory? */ pb.dirInfo.ioNamePtr = tempSpec.name; pb.dirInfo.ioVRefNum = tempSpec.vRefNum; pb.dirInfo.ioDrDirID = tempSpec.parID; pb.dirInfo.ioFDirIndex = 0; result = PBGetCatInfoSync(&pb); // Allow file/directory name at end of path to not exist. realResult = result; if ( (result == noErr) || (result == fnfErr) ) { /* if the object is a directory, append a colon so full pathname ends with colon */ if ( (result == noErr) && (pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 ) { ++tempSpec.name[0]; tempSpec.name[tempSpec.name[0]] = ':'; } /* Put the object name in first */ result = PtrToHand(&tempSpec.name[1], fullPath, tempSpec.name[0]); *fullPathLength = tempSpec.name[0]; if ( result == noErr ) { /* Get the ancestor directory names */ pb.dirInfo.ioNamePtr = tempSpec.name; pb.dirInfo.ioVRefNum = tempSpec.vRefNum; pb.dirInfo.ioDrParID = tempSpec.parID; do /* loop until we have an error or find the root directory */ { pb.dirInfo.ioFDirIndex = -1; pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID; result = PBGetCatInfoSync(&pb); if ( result == noErr ) { /* Append colon to directory name */ ++tempSpec.name[0]; tempSpec.name[tempSpec.name[0]] = ':'; /* Add directory name to beginning of fullPath */ (void) Munger(*fullPath, 0, nil, 0, &tempSpec.name[1], tempSpec.name[0]); *fullPathLength += tempSpec.name[0]; result = MemError(); } } while ( (result == noErr) && (pb.dirInfo.ioDrDirID != fsRtDirID) ); } } } } if ( result == noErr ) { /* Return the length */ /// *fullPathLength = GetHandleSize(*fullPath); result = realResult; // return realResult in case it was fnfErr } else { /* Dispose of the handle and return nil and zero length */ if ( *fullPath != nil ) { DisposeHandle(*fullPath); } *fullPath = nil; *fullPathLength = 0; } return ( result ); }
bool wxSound::DoPlay(unsigned flags) const { Stop(); Movie movie; switch(m_type) { case wxSound_MEMORY: { if (!wxInitQT()) return false; Handle myHandle, dataRef = nil; MovieImportComponent miComponent; Track targetTrack = nil; TimeValue addedDuration = 0; long outFlags = 0; OSErr err; ComponentResult result; myHandle = NewHandleClear((Size)m_waveLength); BlockMove(m_hSnd, *myHandle, m_waveLength); err = PtrToHand(&myHandle, &dataRef, sizeof(Handle)); if (memcmp(&m_hSnd[8], "WAVE", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeWave); else if (memcmp(&m_hSnd[8], "AIFF", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeAIFF); else if (memcmp(&m_hSnd[8], "AIFC", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeAIFC); else { wxLogSysError(wxT("wxSound - Location in memory does not contain valid data")); return false; } movie = NewMovie(0); result = MovieImportDataRef(miComponent, dataRef, HandleDataHandlerSubType, movie, nil, &targetTrack, nil, &addedDuration, movieImportCreateTrack, &outFlags); if (result != noErr) { wxLogSysError(wxString::Format(wxT("Couldn't import movie data\nError:%i"), (int)result)); } SetMovieVolume(movie, kFullVolume); GoToBeginningOfMovie(movie); DisposeHandle(myHandle); } break; case wxSound_RESOURCE: { SoundComponentData data; unsigned long numframes, offset; ParseSndHeader((SndListHandle)m_hSnd, &data, &numframes, &offset); //m_waveLength = numFrames * data.numChannels; SndChannelPtr pSndChannel; SndNewChannel(&pSndChannel, sampledSynth, initNoInterp + (data.numChannels == 1 ? initMono : initStereo), NULL); if(SndPlay(pSndChannel, (SndListHandle) m_hSnd, flags & wxSOUND_ASYNC ? 1 : 0) != noErr) return false; if (flags & wxSOUND_ASYNC) { lastSoundTimer = ((wxSMTimer*&)m_pTimer) = new wxSMTimer(pSndChannel, m_hSnd, flags & wxSOUND_LOOP ? 1 : 0, &lastSoundIsPlaying); lastSoundIsPlaying = true; ((wxTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); } else SndDisposeChannel(pSndChannel, TRUE); return true; } break; case wxSound_FILE: { if (!wxInitQT()) return false; OSErr err = noErr ; Handle dataRef = NULL; OSType dataRefType; err = QTNewDataReferenceFromFullPathCFString(wxMacCFStringHolder(m_sndname,wxLocale::GetSystemEncoding()), (UInt32)kQTNativeDefaultPathStyle, 0, &dataRef, &dataRefType); wxASSERT(err == noErr); if (NULL != dataRef || err != noErr) { err = NewMovieFromDataRef( &movie, newMovieDontAskUnresolvedDataRefs , NULL, dataRef, dataRefType ); wxASSERT(err == noErr); DisposeHandle(dataRef); } if (err != noErr) { wxLogSysError( wxString::Format(wxT("wxSound - Could not open file: %s\nError:%i"), m_sndname.c_str(), err ) ); return false; } } break; default: return false; }//end switch(m_type) //Start the movie! StartMovie(movie); if (flags & wxSOUND_ASYNC) { //Start timer and play movie asyncronously lastSoundTimer = ((wxQTTimer*&)m_pTimer) = new wxQTTimer(movie, flags & wxSOUND_LOOP ? 1 : 0, &lastSoundIsPlaying); lastSoundIsPlaying = true; ((wxQTTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); } else { wxASSERT_MSG(!(flags & wxSOUND_LOOP), wxT("Can't loop and play syncronously at the same time")); //Play movie until it ends, then exit //Note that due to quicktime caching this may not always //work 100% correctly while (!IsMovieDone(movie)) MoviesTask(movie, 1); DisposeMovie(movie); } return true; }
void TLevelWriter3gp::save(const TImageP &img, int frameIndex) { if (m_cancelled) return; TRasterImageP image(img); int lx = image->getRaster()->getLx(); int ly = image->getRaster()->getLy(); //void *buffer = image->getRaster()->getRawData(); int pixSize = image->getRaster()->getPixelSize(); if (pixSize != 4) throw TImageException(getFilePath(), "Unsupported pixel type"); QMutexLocker sl(&m_mutex); if (!m_properties) m_properties = new Tiio::MovWriterProperties(); Tiio::MovWriterProperties *prop = (Tiio::MovWriterProperties *)(m_properties); //CodecType compression = StandardCompressionType; prop->getCurrentCodec(); //CodecQ quality = StandardQualityType; prop->getCurrentQuality(); if (!m_initDone) { //FSSpec fspec; Rect frame; long max_compressed_size; QDErr err; m_videoTrack = NewMovieTrack(m_movie, FixRatio((short)lx, 1), FixRatio((short)ly, 1), kNoVolume); if ((err = GetMoviesError() != noErr)) throw TImageException(getFilePath(), "can't create video track"); m_dataRef = nil; m_hMovieData = NewHandle(0); // Construct the Handle data reference err = PtrToHand(&m_hMovieData, &m_dataRef, sizeof(Handle)); if ((err = GetMoviesError() != noErr)) throw TImageException(getFilePath(), "can't create Data Ref"); m_videoMedia = NewTrackMedia(m_videoTrack, VideoMediaType, (TINT32)m_frameRate, m_dataRef, HandleDataHandlerSubType); OpenADefaultComponent(MovieExportType, '3gpp', &m_myExporter); // err = (short)MovieExportDoUserDialog(m_myExporter, m_movie, 0, 0, 0, &m_cancelled); // if (m_cancelled) // throw TImageException(getFilePath(), "User abort of 3GP render"); if ((err = GetMoviesError() != noErr)) throw TImageException(getFilePath(), "can't create video media"); if ((err = BeginMediaEdits(m_videoMedia)) != noErr) throw TImageException(getFilePath(), "can't begin edit video media"); frame.left = 0; frame.top = 0; frame.right = lx; frame.bottom = ly; #if 0 if ((err = NewGWorld(&(m_gworld), pixSize * 8, &frame, 0, 0, 0))!=noErr) #else /* Mac OSX 10.7 later */ if ((err = QTNewGWorld(&(m_gworld), pixSize * 8, &frame, 0, 0, 0)) != noErr) #endif throw TImageException(getFilePath(), "can't create movie buffer"); #ifdef WIN32 LockPixels(m_gworld->portPixMap); if ((err = GetMaxCompressionSize(m_gworld->portPixMap, &frame, 0, quality, compression, anyCodec, &max_compressed_size)) != noErr) throw TImageException(getFilePath(), "can't get max compression size"); #else #if 0 PixMapHandle pixmapH = GetPortPixMap (m_gworld); LockPixels(pixmapH); #else PixMapHandle pixmapH = NULL; #endif max_compressed_size = lx * ly * 4 * 20; /*if ((err = GetMaxCompressionSize(pixmapH, &frame, 0, quality, compression,anyCodec, &max_compressed_size))!=noErr) throw TImageException(getFilePath(), "can't get max compression size");*/ #endif m_compressedData = NewHandle(max_compressed_size); if ((err = MemError()) != noErr) throw TImageException(getFilePath(), "can't allocate compressed data for movie"); MoveHHi(m_compressedData); HLock(m_compressedData); if ((err = MemError()) != noErr) throw TImageException(getFilePath(), "can't allocate img handle"); #if 0 m_pixmap = GetGWorldPixMap(m_gworld); if (!LockPixels(m_pixmap)) throw TImageException(getFilePath(), "can't lock pixels"); buf = (PixelXRGB*) GetPixBaseAddr(m_pixmap); #else m_pixmap = NULL; buf = NULL; #endif buf_lx = lx; buf_ly = ly; m_initDone = true; } unsigned short rowBytes = (unsigned short)(((short)(*(m_pixmap))->rowBytes & ~(3 << 14))); Rect frame; ImageDescriptionHandle img_descr; Ptr compressed_data_ptr; QDErr err; frame.left = 0; frame.top = 0; frame.right = lx; frame.bottom = ly; TRasterP ras = image->getRaster(); #ifdef WIN32 compressed_data_ptr = StripAddress(*(m_compressedData)); copy(ras, buf, buf_lx, buf_ly); #else compressed_data_ptr = *m_compressedData; copy(ras, buf, buf_lx, buf_ly, rowBytes); #endif img_descr = (ImageDescriptionHandle)NewHandle(4); #ifdef WIN32 if ((err = CompressImage(m_gworld->portPixMap, &frame, quality, compression, img_descr, compressed_data_ptr)) != noErr) throw TImageException(getFilePath(), "can't compress image"); #else #if 0 PixMapHandle pixmapH = GetPortPixMap (m_gworld); if ((err = CompressImage(pixmapH, &frame, codecNormalQuality, kJPEGCodecType, img_descr, compressed_data_ptr))!=noErr) { throw TImageException(getFilePath(), "can't compress image"); } #endif #endif if ((err = AddMediaSample(m_videoMedia, m_compressedData, 0, (*img_descr)->dataSize, 1, (SampleDescriptionHandle)img_descr, 1, 0, 0)) != noErr) throw TImageException(getFilePath(), "can't add image to movie media"); DisposeHandle((Handle)img_descr); }
static pascal OSErr CoerceTargetIDToType (DescType typecode, Ptr dataptr, Size datasize, DescType totype, long refcon, AEDesc *result) { #pragma unused (typecode, datasize, totype) TargetID target; Ptr addressoftype; #if !TARGET_API_MAC_CARBON ProcessSerialNumber psn; ProcessInfoRec info; OSErr ec; #endif BlockMove (dataptr, &target, sizeof (target)); //Code change by Timothy Paustian Sunday, June 25, 2000 10:08:45 PM //This is a bit of a hack but should work. We will just get stuff directly out of //the target rec. I hope this works. Maybe this never gets called in carbon. #if !TARGET_API_MAC_CARBON if (target.location.locationKindSelector == ppcNoLocation) { /*local program*/ ec = GetProcessSerialNumberFromPortName (&target.name, &psn); if (ec != noErr) return (ec); info.processInfoLength = (long) sizeof (info); info.processName = nil; info.processAppSpec = nil; //Code check by Timothy Paustian Tuesday, April 25, 2000 10:20:35 PM //I think this call is OK, but not sure. ec = GetProcessInformation (&psn, &info); if (ec != noErr) return (ec); addressoftype = (Ptr) &info.processSignature; } else { /*not a local program*/ #endif if (target.name.portKindSelector == ppcByCreatorAndType) addressoftype = (Ptr) &target.name.u.port.portCreator; else addressoftype = ((Ptr) &target.name.u.portTypeStr) + 1; /*kloooge*/ #if !TARGET_API_MAC_CARBON } #endif (*result).descriptorType = typeType; #if TARGET_API_MAC_CARBON == 1 /*PBS 03/14/02: AE OS X fix.*/ return (putdescdatapointer (result, typeType, addressoftype, 4)); #else return (PtrToHand (addressoftype, &(*result).dataHandle, 4)); #endif } /*CoerceTargetIDToType*/
void TLevelWriter3gp::saveSoundTrack(TSoundTrack *st) { Track theTrack; OSErr myErr = noErr; SoundDescriptionV1Handle mySampleDesc; Media myMedia; Handle myDestHandle; SoundComponentData sourceInfo; SoundComponentData destInfo; SoundConverter converter; CompressionInfo compressionInfo; int err; if (!st) throw TException("null reference to soundtrack"); if (st->getBitPerSample() != 16) { throw TImageException(m_path, "Only 16 bits per sample is supported"); } theTrack = NewMovieTrack(m_movie, 0, 0, kFullVolume); myErr = GetMoviesError(); if (myErr != noErr) throw TImageException(m_path, "error creating audio track"); FailIf(myErr != noErr, CompressErr); myDestHandle = NewHandle(0); FailWithAction(myDestHandle == NULL, myErr = MemError(), NoDest); *myDestHandle = (char *)st->getRawData(); ////////// // // create a media for the track passed in // ////////// // set new track to be a sound track m_soundDataRef = nil; m_hSoundMovieData = NewHandle(0); // Construct the Handle data reference err = PtrToHand(&m_hSoundMovieData, &m_soundDataRef, sizeof(Handle)); if ((err = GetMoviesError() != noErr)) throw TImageException(getFilePath(), "can't create Data Ref"); myMedia = NewTrackMedia(theTrack, SoundMediaType, st->getSampleRate(), m_soundDataRef, HandleDataHandlerSubType); //track->rate >> 16 myErr = GetMoviesError(); if (myErr != noErr) throw TImageException(m_path, "error setting audio track"); FailIf(myErr != noErr, Exit); // start a media editing session myErr = BeginMediaEdits(myMedia); if (myErr != noErr) throw TImageException(m_path, "error beginning edit audio track"); FailIf(myErr != noErr, Exit); sourceInfo.flags = 0x0; sourceInfo.format = kSoundNotCompressed; sourceInfo.numChannels = st->getChannelCount(); sourceInfo.sampleSize = st->getBitPerSample(); sourceInfo.sampleRate = st->getSampleRate(); sourceInfo.sampleCount = st->getSampleCount(); sourceInfo.buffer = (unsigned char *)st->getRawData(); sourceInfo.reserved = 0x0; destInfo.flags = kNoSampleRateConversion | kNoSampleSizeConversion | kNoSampleFormatConversion | kNoChannelConversion | kNoDecompression | kNoVolumeConversion | kNoRealtimeProcessing; destInfo.format = k16BitNativeEndianFormat; destInfo.numChannels = st->getChannelCount(); destInfo.sampleSize = st->getBitPerSample(); destInfo.sampleRate = st->getSampleRate(); destInfo.sampleCount = st->getSampleCount(); destInfo.buffer = (unsigned char *)st->getRawData(); destInfo.reserved = 0x0; SoundConverterOpen(&sourceInfo, &destInfo, &converter); myErr = SoundConverterGetInfo(converter, siCompressionFactor, &compressionInfo); if (myErr != noErr) throw TImageException(m_path, "error getting audio converter info"); myErr = GetCompressionInfo(fixedCompression, sourceInfo.format, sourceInfo.numChannels, sourceInfo.sampleSize, &compressionInfo); if (myErr != noErr) throw TImageException(m_path, "error getting audio compression info"); FailIf(myErr != noErr, ConverterErr); compressionInfo.bytesPerFrame = compressionInfo.bytesPerPacket * destInfo.numChannels; ////////// // // create a sound sample description // ////////// // use the SoundDescription format 1 because it adds fields for data size information // and is required by AddSoundDescriptionExtension if an extension is required for the compression format mySampleDesc = (SoundDescriptionV1Handle)NewHandleClear(sizeof(SoundDescriptionV1)); FailWithAction(myErr != noErr, myErr = MemError(), Exit); (**mySampleDesc).desc.descSize = sizeof(SoundDescriptionV1); (**mySampleDesc).desc.dataFormat = destInfo.format; (**mySampleDesc).desc.resvd1 = 0; (**mySampleDesc).desc.resvd2 = 0; (**mySampleDesc).desc.dataRefIndex = 1; (**mySampleDesc).desc.version = 1; (**mySampleDesc).desc.revlevel = 0; (**mySampleDesc).desc.vendor = 0; (**mySampleDesc).desc.numChannels = destInfo.numChannels; (**mySampleDesc).desc.sampleSize = destInfo.sampleSize; (**mySampleDesc).desc.compressionID = 0; (**mySampleDesc).desc.packetSize = 0; (**mySampleDesc).desc.sampleRate = st->getSampleRate() << 16; (**mySampleDesc).samplesPerPacket = compressionInfo.samplesPerPacket; (**mySampleDesc).bytesPerPacket = compressionInfo.bytesPerPacket; (**mySampleDesc).bytesPerFrame = compressionInfo.bytesPerFrame; (**mySampleDesc).bytesPerSample = compressionInfo.bytesPerSample; ////////// // // add samples to the media // ////////// myErr = AddMediaSample(myMedia, myDestHandle, 0, destInfo.sampleCount * compressionInfo.bytesPerFrame, 1, (SampleDescriptionHandle)mySampleDesc, destInfo.sampleCount * compressionInfo.samplesPerPacket, 0, NULL); if (myErr != noErr) throw TImageException(m_path, "error adding audio samples"); FailIf(myErr != noErr, MediaErr); myErr = EndMediaEdits(myMedia); if (myErr != noErr) throw TImageException(m_path, "error ending audio edit"); FailIf(myErr != noErr, MediaErr); ////////// // // insert the media into the track // ////////// myErr = InsertMediaIntoTrack(theTrack, 0, 0, GetMediaDuration(myMedia), fixed1); if (myErr != noErr) throw TImageException(m_path, "error inserting audio track"); FailIf(myErr != noErr, MediaErr); goto Done; ConverterErr: NoDest: CompressErr: Exit: Done: MediaErr: if (mySampleDesc != NULL) DisposeHandle((Handle)mySampleDesc); if (converter) SoundConverterClose(converter); if (myErr != noErr) throw TImageException(m_path, "error saving audio track"); }
static IconRef CreateIconRefFromImage (CGImageRef srcImage, CGRect srcRect) { OSStatus err; CGContextRef cctx, actx; CGColorSpaceRef color; CGRect dstRect; IconRef iconRef; IconFamilyHandle icns; Handle hdl; SInt32 size; UInt32 rgb[kIconSize * kIconSize]; UInt8 alp[kIconSize * kIconSize]; srcRect.origin.y = CGImageGetHeight(srcImage) - srcRect.origin.y - kIconSize; color = CGColorSpaceCreateDeviceRGB(); if (color) { cctx = CGBitmapContextCreate(rgb, kIconSize, kIconSize, 8, kIconSize * 4, color, kCGImageAlphaNoneSkipFirst); if (cctx) { dstRect = CGRectMake(0, 0, kIconSize, kIconSize); DrawSubCGImage(cctx, srcImage, srcRect, dstRect); actx = CGBitmapContextCreate(alp, kIconSize, kIconSize, 8, kIconSize, NULL, kCGImageAlphaOnly); if (actx) { DrawSubCGImage(actx, srcImage, srcRect, dstRect); CGContextRelease(actx); } CGContextRelease(cctx); } CGColorSpaceRelease(color); } iconRef = NULL; size = sizeof(OSType) + sizeof(SInt32); icns = (IconFamilyHandle) NewHandle(size); if (icns) { // Big-endian: Panther is for PowerPC only (*icns)->resourceType = kIconFamilyType; (*icns)->resourceSize = size; err = PtrToHand(rgb, &hdl, sizeof(rgb)); if (err == noErr) { err = SetIconFamilyData(icns, kSmall32BitData, hdl); DisposeHandle(hdl); if (err == noErr) { err = PtrToHand(alp, &hdl, sizeof(alp)); if (err == noErr) { err = SetIconFamilyData(icns, kSmall8BitMask, hdl); DisposeHandle(hdl); } } } if (err == noErr) err = GetIconRefFromIconFamilyPtr(*icns, GetHandleSize((Handle) icns), &iconRef); DisposeHandle((Handle) icns); } return (iconRef); }
static HRESULT QT_Process_Movie(QTSplitter* filter) { HRESULT hr = S_OK; OSErr err; WineDataRefRecord ptrDataRefRec; Handle dataRef = NULL; Track trk; short id = 0; DWORD tid; LONGLONG time; TRACE("Trying movie connect\n"); ptrDataRefRec.pReader = filter->pInputPin.pReader; ptrDataRefRec.streamSubtype = filter->pInputPin.subType; PtrToHand( &ptrDataRefRec, &dataRef, sizeof(WineDataRefRecord)); err = NewMovieFromDataRef(&filter->pQTMovie, newMovieActive|newMovieDontInteractWithUser|newMovieDontAutoUpdateClock|newMovieDontAskUnresolvedDataRefs|newMovieAsyncOK, &id, dataRef, 'WINE'); DisposeHandle(dataRef); if (err != noErr) { FIXME("QuickTime cannot handle media type(%i)\n",err); return VFW_E_TYPE_NOT_ACCEPTED; } PrePrerollMovie(filter->pQTMovie, 0, fixed1, NULL, NULL); PrerollMovie(filter->pQTMovie, 0, fixed1); GoToBeginningOfMovie(filter->pQTMovie); SetMovieActive(filter->pQTMovie,TRUE); if (GetMovieLoadState(filter->pQTMovie) < kMovieLoadStateLoaded) MoviesTask(filter->pQTMovie,100); trk = GetMovieIndTrackType(filter->pQTMovie, 1, VisualMediaCharacteristic, movieTrackCharacteristic | movieTrackEnabledOnly); TRACE("%p is a video track\n",trk); if (trk) hr = QT_Process_Video_Track(filter, trk); if (FAILED(hr)) return hr; trk = GetMovieIndTrackType(filter->pQTMovie, 1, AudioMediaCharacteristic, movieTrackCharacteristic | movieTrackEnabledOnly); TRACE("%p is a audio track\n",trk); if (trk) hr = QT_Process_Audio_Track(filter, trk); time = GetMovieDuration(filter->pQTMovie); filter->movie_scale = GetMovieTimeScale(filter->pQTMovie); filter->sourceSeeking.llDuration = ((double)time / filter->movie_scale) * 10000000; filter->sourceSeeking.llStop = filter->sourceSeeking.llDuration; TRACE("Movie duration is %s\n",wine_dbgstr_longlong(filter->sourceSeeking.llDuration)); filter->loaderThread = CreateThread(NULL, 0, QTSplitter_loading_thread, filter, 0, &tid); if (filter->loaderThread) TRACE("Created loading thread 0x%08x\n", tid); filter->splitterThread = CreateThread(NULL, 0, QTSplitter_thread, filter, 0, &tid); if (filter->splitterThread) TRACE("Created processing thread 0x%08x\n", tid); else hr = HRESULT_FROM_WIN32(GetLastError()); return hr; }
int DoHostListDialog() { short itemHit,okay=FALSE,keepGoing=TRUE; DialogPtr dlog=NIL; GrafPtr oldPort; ModalFilterUPP MyFilterUPP; GetPort(&oldPort); /* On PowerPC, need a RoutineDescriptor from heap; on 68K, no allocation */ MyFilterUPP = NewModalFilterProc(MyFilterHD); if (MyFilterUPP == NIL) goto cleanUp; /* Build dialog window and install its item values */ OpenPrefsFile(); dlog = OpenThisDialog(); if (dlog == NIL) goto cleanUp; /* Entertain filtered user events until dialog is dismissed */ while (keepGoing) { ModalDialog(MyFilterUPP,&itemHit); keepGoing = DoDialogItem(dlog,itemHit); } /* * Do final processing of item values, such as exporting them to caller. * DoDialogItem() has already called AnyBadValues(). */ if (itemHit == OK_ITEM) { Point theCell; short dataLen; OSErr anErr; Handle aHand; // get the current selection and store it in a global which can be accessed // from the application theCell.h = 0; theCell.v = list4.currentRow; dataLen = 255; LGetCell(&gSavedSelection[1], &dataLen, theCell, list4.hndl); gSavedSelection[0] = dataLen; // we save the current selection for the next time we use this transport // remove the current resource aHand = Get1Resource('mw2H', 1000); if (aHand != nil) { RemoveResource(aHand); DisposeHandle(aHand); aHand = nil; } // create a handle and add this resource to the resource file anErr = PtrToHand(&gSavedSelection[0], &aHand, gSavedSelection[0] + 1); // name and length byte if ( (anErr == noErr) && (aHand != nil) ) { AddResource(aHand, 'mw2H', 1000, "\pDefault Host"); WriteResource(aHand); }
bool wxOSXQuickTimeSoundData::Play(unsigned flags) { if ( m_movie ) Stop(); m_flags = flags; if (!wxInitQT()) return false; if( m_soundHandle ) { Handle dataRef = nil; MovieImportComponent miComponent; Track targetTrack = nil; TimeValue addedDuration = 0; long outFlags = 0; OSErr err; ComponentResult result; err = PtrToHand(&m_soundHandle, &dataRef, sizeof(Handle)); HLock(m_soundHandle); if (memcmp(&(*m_soundHandle)[8], "WAVE", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeWave); else if (memcmp(&(*m_soundHandle)[8], "AIFF", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeAIFF); else if (memcmp(&(*m_soundHandle)[8], "AIFC", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeAIFC); else { HUnlock(m_soundHandle); wxLogSysError(wxT("wxSound - Location in memory does not contain valid data")); return false; } HUnlock(m_soundHandle); m_movie = NewMovie(0); result = MovieImportDataRef(miComponent, dataRef, HandleDataHandlerSubType, m_movie, nil, &targetTrack, nil, &addedDuration, movieImportCreateTrack, &outFlags); if (result != noErr) { wxLogSysError(wxString::Format(wxT("Couldn't import movie data\nError:%i"), (int)result)); } SetMovieVolume(m_movie, kFullVolume); GoToBeginningOfMovie(m_movie); } else { OSErr err = noErr ; Handle dataRef = NULL; OSType dataRefType; err = QTNewDataReferenceFromFullPathCFString(wxCFStringRef(m_sndname,wxLocale::GetSystemEncoding()), (UInt32)kQTNativeDefaultPathStyle, 0, &dataRef, &dataRefType); wxASSERT(err == noErr); if (NULL != dataRef || err != noErr) { err = NewMovieFromDataRef( &m_movie, newMovieDontAskUnresolvedDataRefs , NULL, dataRef, dataRefType ); wxASSERT(err == noErr); DisposeHandle(dataRef); } if (err != noErr) { wxLogSysError( wxString::Format(wxT("wxSound - Could not open file: %s\nError:%i"), m_sndname.c_str(), err ) ); return false; } } //Start the m_movie! StartMovie(m_movie); if (flags & wxSOUND_ASYNC) { CreateAndStartTimer(); } else { wxASSERT_MSG(!(flags & wxSOUND_LOOP), wxT("Can't loop and play syncronously at the same time")); //Play movie until it ends, then exit //Note that due to quicktime caching this may not always //work 100% correctly while (!IsMovieDone(m_movie)) MoviesTask(m_movie, 1); DoStop(); } return true; }