Esempio n. 1
0
Handle QTDR_MakeResourceDataRef (FSSpecPtr theFile, OSType theResType, SInt16 theResID)
{
	Handle			myDataRef = NULL;
	OSType			myResType;
	SInt16			myResID;
	OSErr			myErr = noErr;

	myDataRef = QTDR_MakeFileDataRef(theFile);
	if (myDataRef == NULL)
    	goto bail;

	// append the resource type and ID to the data reference
	myResType = EndianU32_NtoB(theResType);
	myResID = EndianS16_NtoB(theResID);
	
	myErr = PtrAndHand(&myResType, myDataRef, sizeof(myResType));
	if (myErr == noErr)
		myErr = PtrAndHand(&myResID, myDataRef, sizeof(myResID));

bail:
	if (myErr != noErr) {
		if (myDataRef != NULL)
			DisposeHandle(myDataRef);
		myDataRef = NULL;
	}
	
	return(myDataRef);
}
Esempio n. 2
0
static void set_instrument(MidiEvent *ev)
{
	long instrumentNumber;
	int ch = ev->channel;

	channel[ch].program = ev->a;
	if(drum_part[ch]){
		if(play_system_mode == GS_SYSTEM_MODE && channel[ch].bank_lsb == 2)				// SC-88 Map
			instrumentNumber = kFirstDrumkit + sc88_drum_kit[ev->a] + 1;
		else if(play_system_mode == GS_SYSTEM_MODE && channel[ch].bank_lsb == 3)		// SC-88Pro Map
			instrumentNumber = kFirstDrumkit + sc88pro_drum_kit[ev->a] + 1;
		else
			instrumentNumber = kFirstDrumkit + ev->a + 1;
	}
	else {
		if(play_system_mode == GS_SYSTEM_MODE)
			instrumentNumber = kFirstGSInstrument + (channel[ch].bank_msb<<7) + ev->a;
		else if(play_system_mode == XG_SYSTEM_MODE)
			instrumentNumber = xg_instrument_number(ch, ev->a);
		else
			instrumentNumber = kFirstGMInstrument + ev->a;
	}
	if(instrument_number[ch] != instrumentNumber){
		NoteRequest	nr;
		long index,  part;
		OSType synthType;
		Str31 name;
		SynthesizerConnections connections;
		MusicComponent mc;

		instrument_number[ch] = instrumentNumber;
		if(note_channel[ch] != NULL)
			NADisposeNoteChannel(gNoteAllocator, note_channel[ch]);
		nr.info.flags = 0;
		nr.info.reserved = 0;
		*(short *)(&nr.info.polyphony) = EndianS16_NtoB(8);			// 8 voices poliphonic
		*(Fixed *)(&nr.info.typicalPolyphony) = EndianU32_NtoB(0x00010000);
		NAStuffToneDescription(gNoteAllocator, instrumentNumber, &nr.tone);
		NANewNoteChannel(gNoteAllocator, &nr, &note_channel[ch]);
		NAGetNoteChannelInfo(gNoteAllocator, note_channel[ch], &index, &part);
		NAGetRegisteredMusicDevice(gNoteAllocator, index, &synthType, name, &connections, &mc);
		MusicGetPartName(mc, part, name);
		p2cstrcpy(instrument_name[ch], name);
	}
	ctl_prog_event(ch, ev->a);
}
OSErr SpriteUtils_SetSpriteData (QTAtomContainer theSprite, Point *theLocation, short *theVisible, short *theLayer, short *theImageIndex, ModifierTrackGraphicsModeRecord *theGraphicsMode, StringPtr theSpriteName, QTAtomContainer theActionAtoms)
{
	QTAtom				myPropertyAtom;
	OSErr				myErr = noErr;
	
	if (theSprite == NULL)
		return(paramErr);
		
	// set the sprite location data
	if (theLocation != NULL) {
		MatrixRecord	myMatrix;
		
		SetIdentityMatrix(&myMatrix);
		myMatrix.matrix[2][0] = ((long)theLocation->h << 16);
		myMatrix.matrix[2][1] = ((long)theLocation->v << 16);
		EndianUtils_MatrixRecord_NtoB(&myMatrix);

		myPropertyAtom = QTFindChildByIndex(theSprite, kParentAtomIsContainer, kSpritePropertyMatrix, 1, NULL);
		if (myPropertyAtom == 0)
			myErr = QTInsertChild(theSprite, kParentAtomIsContainer, kSpritePropertyMatrix, 1, 0, sizeof(MatrixRecord), &myMatrix, NULL);
		else
			myErr = QTSetAtomData(theSprite, myPropertyAtom, sizeof(MatrixRecord), &myMatrix);
			
		if (myErr != noErr)
			goto bail;
	}
	
	// set the sprite visibility state
	if (theVisible != NULL) {
		short 			myVisible = *theVisible;
		
		myVisible = EndianS16_NtoB(myVisible);
		
		myPropertyAtom = QTFindChildByIndex(theSprite, kParentAtomIsContainer, kSpritePropertyVisible, 1, NULL);
		if (myPropertyAtom == 0)
			myErr = QTInsertChild(theSprite, kParentAtomIsContainer, kSpritePropertyVisible, 1, 0, sizeof(short), &myVisible, NULL);
		else
			myErr = QTSetAtomData(theSprite, myPropertyAtom, sizeof(short), &myVisible);
			
		if (myErr != noErr)
			goto bail;
	}
	
	// set the sprite layer
	if (theLayer != NULL) {
		short 			myLayer = *theLayer;
		
		myLayer = EndianS16_NtoB(myLayer);

		myPropertyAtom = QTFindChildByIndex(theSprite, 0, kSpritePropertyLayer, 1, NULL);
		if (myPropertyAtom == 0)
			myErr = QTInsertChild(theSprite, 0, kSpritePropertyLayer, 1, 0, sizeof(short), &myLayer, NULL);
		else
			myErr = QTSetAtomData(theSprite, myPropertyAtom, sizeof(short), &myLayer);
			
		if (myErr != noErr)
			goto bail;
	}
	
	// set the sprite image index
	if (theImageIndex != NULL) {
		short 			myImageIndex = *theImageIndex;

		myImageIndex = EndianS16_NtoB(myImageIndex);
		
		myPropertyAtom = QTFindChildByIndex(theSprite, kParentAtomIsContainer, kSpritePropertyImageIndex, 1, NULL);
		if (myPropertyAtom == 0)
			myErr = QTInsertChild(theSprite, kParentAtomIsContainer, kSpritePropertyImageIndex, 1, 0, sizeof(short), &myImageIndex, NULL);
		else
			myErr = QTSetAtomData(theSprite, myPropertyAtom, sizeof(short), &myImageIndex);
			
		if (myErr != noErr)
			goto bail;
	}
	
	// set the sprite graphics mode
	if (theGraphicsMode != NULL) {
		ModifierTrackGraphicsModeRecord		myGraphicsMode;
		
		myGraphicsMode.graphicsMode = EndianU32_NtoB(theGraphicsMode->graphicsMode);
		myGraphicsMode.opColor.red = EndianU16_NtoB(theGraphicsMode->opColor.red);
		myGraphicsMode.opColor.green = EndianU16_NtoB(theGraphicsMode->opColor.green);
		myGraphicsMode.opColor.blue = EndianU16_NtoB(theGraphicsMode->opColor.blue);

		myPropertyAtom = QTFindChildByIndex(theSprite, kParentAtomIsContainer, kSpritePropertyGraphicsMode, 1, NULL);
		if (myPropertyAtom == 0)
			myErr = QTInsertChild(theSprite, kParentAtomIsContainer, kSpritePropertyGraphicsMode, 1, 0, sizeof(myGraphicsMode), &myGraphicsMode, NULL);
		else
			myErr = QTSetAtomData(theSprite, myPropertyAtom, sizeof(myGraphicsMode), &myGraphicsMode);
			
		if (myErr != noErr)
			goto bail;
	}
	
	// set the sprite name
	if (theSpriteName != NULL) {
		QTAtom 		mySpriteNameAtom;
		
		mySpriteNameAtom = QTFindChildByIndex(theSprite, kParentAtomIsContainer, kSpriteNameAtomType, 1, NULL);
		if (mySpriteNameAtom == 0)
			myErr = QTInsertChild(theSprite, kParentAtomIsContainer, kSpriteNameAtomType, 1, 0, theSpriteName[0] + 1, theSpriteName, NULL);
		else
			myErr = QTSetAtomData(theSprite, mySpriteNameAtom, theSpriteName[0] + 1, theSpriteName);

		if (myErr != noErr)
			goto bail;
	}
	
	// set the action atoms
	if (theActionAtoms != NULL)
		myErr = QTInsertChildren(theSprite, kParentAtomIsContainer, theActionAtoms);
	
bail:
	if ((myErr != noErr) && (theSprite != NULL))
		QTRemoveChildren(theSprite, 0);

	return(myErr);
}
Esempio n. 4
0
OSErr QTInfo_MakeFilePreview (Movie theMovie, short theRefNum, ICMProgressProcRecordPtr theProgressProc)
{
    unsigned long			myModDate;
    PreviewResourceRecord	myPNOTRecord;
    long					myEOF;
    long					mySize;
    unsigned long			myAtomHeader[2];	// an atom header: size and type
    OSType					myPreviewType;
    OSErr					myErr = noErr;

    //////////
    //
    // determine whether theRefNum is a file reference number of a data fork or a resource fork;
    // if it's a resource fork, then we'll just call the existing ICM function MakeFilePreview
    //
    //////////

    if (QTInfo_IsRefNumOfResourceFork(theRefNum)) {
        myErr = MakeFilePreview(theRefNum, theProgressProc);
        goto bail;
    }

    //////////
    //
    // determine the preview type
    //
    //////////

    // if the movie has a movie preview, use that as the file preview; otherwise use a thumbnail
    // of the movie poster frame as the file preview
    if (QTInfo_MovieHasPreview(theMovie))
        myPreviewType = MovieAID;
    else
        myPreviewType = kQTFileTypePicture;

    //////////
    //
    // construct the 'pnot' atom
    //
    //////////

    // fill in the 'pnot' atom header
    myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + sizeof(myPNOTRecord));
    myAtomHeader[1] = EndianU32_NtoB(ShowFilePreviewComponentType);

    // fill in the 'pnot' atom data
    GetDateTime(&myModDate);

    myPNOTRecord.modDate = EndianU32_NtoB(myModDate);		// the modification time of the preview
    myPNOTRecord.version = EndianS16_NtoB(0);				// version number; must be 0
    myPNOTRecord.resType = EndianU32_NtoB(myPreviewType);	// atom type containing preview
    myPNOTRecord.resID = EndianS16_NtoB(1);					// the 1-based index of the atom of the specified type to use

    //////////
    //
    // write the 'pnot' atom at the end of the data fork
    //
    //////////

    // get the current logical end-of-file and extend it by the desired amount
    myErr = GetEOF(theRefNum, &myEOF);
    if (myErr != noErr)
        goto bail;

    myErr = SetEOF(theRefNum, myEOF + sizeof(myAtomHeader) + sizeof(myPNOTRecord));
    if (myErr != noErr)
        goto bail;

    // set the file mark
    myErr = SetFPos(theRefNum, fsFromStart, myEOF);
    if (myErr != noErr)
        goto bail;

    // write the atom header into the file
    mySize = sizeof(myAtomHeader);
    myErr = FSWrite(theRefNum, &mySize, myAtomHeader);
    if (myErr != noErr)
        goto bail;

    // write the atom data into the file
    mySize = sizeof(myPNOTRecord);
    myErr = FSWrite(theRefNum, &mySize, &myPNOTRecord);
    if (myErr != noErr)
        goto bail;

    //////////
    //
    // write the preview data atom at the end of the data fork
    //
    //////////

    if (myPreviewType == MovieAID) {
        // in theory, we don't need to do anything here, since our 'pnot' atom points
        // to the 'moov' atom; in practice, this doesn't work correctly (it seems like
        // a bug in StandardGetFilePreview)
    }

    if (myPreviewType == kQTFileTypePicture) {
        PicHandle		myPicture = NULL;
        PicHandle		myThumbnail = NULL;

        // get the poster frame picture
        myPicture = GetMoviePosterPict(theMovie);
        if (myPicture != NULL) {

            // create a thumbnail
            myThumbnail = (PicHandle)NewHandleClear(4);
            if (myThumbnail != NULL) {
                myErr = MakeThumbnailFromPicture(myPicture, 0, myThumbnail, theProgressProc);
                if (myErr == noErr) {

                    myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + GetHandleSize((Handle)myThumbnail));
                    myAtomHeader[1] = EndianU32_NtoB(myPreviewType);

                    // write the atom header into the file
                    mySize = sizeof(myAtomHeader);
                    myErr = FSWrite(theRefNum, &mySize, myAtomHeader);
                    if (myErr == noErr) {
                        // write the atom data into the file
                        mySize = GetHandleSize((Handle)myThumbnail);
                        myErr = FSWrite(theRefNum, &mySize, *myThumbnail);
                    }
                }

                KillPicture(myThumbnail);
            }

            KillPicture(myPicture);
        }
    }

#if 0
    // here's how you'd add a text preview; note that the text is hard-coded here....
    if (myPreviewType == kQTFileTypeText) {
        char 	myText[] = "The penguin gradually appears from the mist of the ice floe.";

        myAtomHeader[0] = EndianU32_NtoB(sizeof(myAtomHeader) + strlen(myText));
        myAtomHeader[1] = EndianU32_NtoB(myPreviewType);

        // write the atom header into the file
        mySize = sizeof(myAtomHeader);
        myErr = FSWrite(theRefNum, &mySize, myAtomHeader);
        if (myErr != noErr)
            goto bail;

        // write the atom data into the file
        mySize = strlen(myText);
        myErr = FSWrite(theRefNum, &mySize, myText);
        if (myErr != noErr)
            goto bail;
    }
#endif

#if TARGET_OS_MAC
    if (myErr == noErr) {
        short				myVolNum;

        // flush the volume
        myErr = GetVRefNum(theRefNum, &myVolNum);
        if (myErr != noErr)
            goto bail;

        myErr = FlushVol(NULL, myVolNum);
    }
#endif

bail:
    return(myErr);
}