Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
•QTMusic Sample Sequencer/SequencerTest Filing.c
/* |
* file: SequencerTest Filing.c |
* |
* started 12 January 1992 09:34 |
* david van brink |
* |
* The filing routines |
* |
*/ |
/*-------------------------- |
Inclusions |
--------------------------*/ |
#include <Files.h> |
#include <StandardFile.h> |
#include <Resources.h> |
#include <Errors.h> |
#include <Memory.h> |
#include "BigEasy2.h" |
#include "BigEasyDialogs.h" |
#include "SequencerTest.h" |
#include "SequencerTest Filing.h" |
/*-------------------------- |
Local Prototypes |
--------------------------*/ |
OSErr InternalSaveData(TDoc *d); |
void UpdateSaveRecordFromEarlierVersion(TSaveRecord **sr); |
/*-------------------------- |
Wasabe |
--------------------------*/ |
void OpenDoc(short n,short item, short ref) |
{ |
StandardFileReply sfr; |
OSType ourType[5]; |
ourType[0] = kDocumentFileType; |
StandardGetFile(nil,1,ourType,&sfr); |
if(sfr.sfGood) |
{ |
OpenDocSpec(&sfr.sfFile); |
} |
} |
void OpenDocSpec(FSSpec *fSpec) |
{ |
short i; |
short refNum; |
register TDoc *d; |
TSaveRecord **sr; |
FInfo fileInfo; |
for(i = 0; i<kDocMax; i++) |
{ |
d = &gDoc[i]; |
if(!d->used) |
goto gotOne; |
} |
EasyDialogMessage(0,(StringPtr)0x910,"\pNo more windows may be opened.", |
kEasyDialogOkay); |
goto goHome; |
gotOne: |
refNum = FSpOpenResFile(fSpec,fsRdPerm); |
if(refNum == 1) |
goto fileError; |
sr = (void *)Get1IndResource(kDocumentResType,1); |
if(!sr) |
goto closeAndFileError; |
HLock((void *)sr); |
if((**sr).docVersion != kDocVersion) |
{ |
EasyDialogMessage(0,fSpec->name, |
"\pThat was an old version of the file format.", |
kEasyDialogOkay); |
goto closeAndFileError; |
} |
UpdateSaveRecordFromEarlierVersion(sr); |
d->used = true; |
d->docSpec = *fSpec; |
NewDocFromSaveRecord(i,&(**sr)); |
goto goHome; |
closeAndFileError: |
CloseResFile(refNum); |
fileError: |
EasyDialogMessage(0,fSpec->name, |
"\pThere was a problem opening the file.", |
kEasyDialogOkay); |
goHome:; |
} |
short SaveDoc(short n,short item, short ref) |
/* |
* return nonzero to |
* say it was cancelled. |
*/ |
{ |
TDoc *d; |
d = &gDoc[n - kFirstDocWindow]; |
if(!d->everSaved) |
return SaveAsDoc(n,item,ref); |
else |
return InternalSaveData(d); |
} |
short SaveAsDoc(short n,short item, short ref) |
{ |
StandardFileReply sfr; |
register TDoc *d; |
Boolean result; |
TSaveRecord *sr,**srH; |
short refNum; |
OSErr thisError; |
OSType fileType; |
d = &gDoc[n - kFirstDocWindow]; |
StandardPutFile("\p",d->docSpec.name,&sfr); |
result = !sfr.sfGood; |
if(sfr.sfGood) |
{ |
d->docSpec = sfr.sfFile; |
SetWTitle(d->w,d->docSpec.name); |
thisError = InternalSaveData(d); |
} |
else |
thisError = 1; |
return thisError; |
} |
OSErr InternalSaveData(TDoc *d) |
{ |
TSaveRecord **srH,*sr; |
short refNum; |
OSErr thisError; |
Rect r; |
srH = (void *)NewHandle(sizeof(TSaveRecord)); |
HLock((void *)srH); |
sr = *srH; |
sr->docVersion = kDocVersion; |
SetPort(d->w); |
sr->windowRect = qd.thePort->portRect; |
LocalToGlobal((Point *)&sr->windowRect.top); |
LocalToGlobal((Point *)&sr->windowRect.bottom); |
sr->sr = d->sr; |
HUnlock((void *)srH); |
FSpCreateResFile(&d->docSpec,kCreatorFileType,kDocumentFileType,0); |
thisError = ResError(); |
if(thisError == dupFNErr) |
thisError = 0; |
if(thisError) |
goto goHome; |
refNum = FSpOpenResFile(&d->docSpec,fsRdWrPerm); |
if(refNum != -1) |
{ |
Replace1Resource((void *)srH,kDocumentResType,10); |
CloseResFile(refNum); |
d->changed = false; |
d->littleChanged = false; |
d->everSaved = true; |
FixUpMenus(d); |
} |
else |
thisError = -1; |
goHome: |
return thisError; |
} |
#define kScorePartSize (sizeof(ScorePart)) |
#define kOldScorePartSize (sizeof(ScorePart)-4) |
#define kShift (4) |
void UpdateSaveRecordFromEarlierVersion(TSaveRecord **sr) |
{ |
long size; |
Ptr x; |
ToneDescription *td; |
short i; |
size = GetHandleSize((Handle)sr); |
if(size < sizeof(TSaveRecord) ) |
{ |
SetHandleSize((Handle)sr,sizeof(TSaveRecord)); |
HLock((Handle)sr); |
x = (Ptr)*sr; |
x += sizeof(TSaveRecord); |
for(i = 4; i >=1; i--) |
{ |
x -= kScorePartSize; |
BlockMove(x - kShift * i,x,kOldScorePartSize); |
td = (ToneDescription *)x; |
td->synthesizerType = 0; |
td->synthesizerName[0] = 0; |
td->instrumentName[0] = 0; |
td->instrumentNumber = 0; |
td->gmNumber = 1; |
} |
} |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-03-19