#pragma optimize -1#pragma noroot#include "defines.h"#include #include #include #include #include #include #include /* This is how saved files are stored: */struct InOutRec{ Word ByteOrder; Word Version; Word Capo; Word __reserved[5]; Word StrCount; Word Strings[]; /* ... */ Word CommentLength; char Comment[];};typedef struct InOutRec InOutRec, *InOutRecPtr, **InOutRecHandle;extern int MyID;extern int strcount;extern int stringsSTD[MAXSTRINGS];extern int Capo;extern void Update (void);extern void MoveCapo (void);extern CreateRecGS CreateOS;extern RefNumRecGS CloseOS;extern IORecGS RWOS;extern OpenRecGS OpenOS;extern NameRecGS DestroyOS;extern ResultBuf32 SFname;extern ResultBuf255 SFpath;extern SFReplyRec2 MyReplyRec;extern SFTypeList2 TypeList;Word OpenIt (GSString255Ptr);GSString255Ptr pString2gs (char *);/* Check if there's a message for me, and if so, open the file */void HandleMessage (void){Handle Msg;Pointer mPtr;GSString255Ptr tmp; Msg = NewHandle (0, MyID, attrNoCross, 0); MessageCenter (getMessage, 1, Msg); mPtr = *Msg; if (!_toolErr) { if ( ((MessageRecPtr)mPtr)->messageType == 1) { if (OpenIt (pString2gs ((char *) (mPtr + 8)))) MessageCenter (deleteMessage, 1, 0); } else if ( ((MessageRecPtr)mPtr)->messageType == 0x11) { if (OpenIt ( (GSString255Ptr) (mPtr + 8))) MessageCenter (deleteMessage, 1, 0); } } DisposeHandle ((Handle) Msg); return;}GSString255Ptr pString2gs (char *the_file_name){ static GSString255 string; string.length = the_file_name[0]; BlockMove ((Pointer) & the_file_name[1], (Pointer) (&string) + 2, string.length); //move the string into it return &string;}/*void LoadBuffer (void){ MyInOutRec.Version = 1; MyInOutRec.StrCount = strcount; MyInOutRec.Capo = Capo; BlockMove ((Pointer) & stringsSTD, (Pointer) & MyInOutRec.Strings, 12);}*//*void UnLoadBuffer (void){ if (MyInOutRec.Version == 1) { strcount = MyInOutRec.StrCount; Capo = MyInOutRec.Capo; BlockMove ((Pointer) & MyInOutRec.Strings, (Pointer) & stringsSTD, 12); SetControls (); }}*/Word OpenIt (GSString255Ptr filename){handle elyssa;pointer emily;int tmp; OpenOS.requestAccess = readEnable; OpenOS.pathname = filename; OpenGS (&OpenOS); if (_toolErr) { AlertWindow (4, NULL, OpenErr); return 0; }/* only valid iff from Message Centre */ if ( (OpenOS.auxType != MyAuxType) || (OpenOS.fileType != MyFileType)) return 0; RWOS.refNum = CloseOS.refNum = OpenOS.refNum; if (!OpenOS.eof) { AlertWindow (4, NULL, EmptyErr); return 0; } else { elyssa = NewHandle (OpenOS.eof, MyID, 0xc018, NULL); if (_toolErr) { AlertWindow (4, NULL, MemErr); return 0; } emily = *elyssa; } RWOS.requestCount = OpenOS.eof; RWOS.dataBuffer = emily; ReadGS (&RWOS); if (_toolErr) { CloseGS (&CloseOS); DisposeHandle (elyssa); AlertWindow (4, NULL, ReadErr); return 0; } CloseGS (&CloseOS);/* is it big endian? */ if ( ((InOutRecPtr)emily)->ByteOrder == 0x3412) swap (emily); else if ( ((InOutRecPtr)emily)->ByteOrder != 0x1234) { AlertWindow (4, NULL, CorruptErr); DisposeHandle (elyssa); return 0; }/* check the version number */ if ( ((InOutRecPtr)emily)->Version != 1) { AlertWindow (4, NULL, VersionErr); DisposeHandle (elyssa); return 0; } if ( ((InOutRecPtr)emily)->Capo > 11 || ((InOutRecPtr)emily)->Capo < 0) { AlertWindow (4, NULL, CorruptErr); DisposeHandle (elyssa); return 0; } if ( ((InOutRecPtr)emily)->StrCount > MAXSTRINGS || ((InOutRecPtr)emily)->StrCount < MINSTRINGS) { AlertWindow (4, NULL, CorruptErr); DisposeHandle (elyssa); return 0; } Capo = ((InOutRecPtr)emily)->Capo; strcount = ((InOutRecPtr)emily)->StrCount; for (tmp = 0; tmp < strcount; tmp++) stringsSTD[tmp] = ((InOutRecPtr)emily)->Strings[tmp];/* set the comment (if any) */ tmp = * ((int *) (emily + 18 + (strcount << 1))); /* get the size */ if (tmp) TESetText (5, (Ref)(emily + 20 + (strcount << 1)), (long)tmp, 0, NULL, (Handle) GetCtlHandleFromID (NULL, kCommentField)); else TESetText (5, NULL, 0, 0, NULL, (Handle) GetCtlHandleFromID (NULL, kCommentField)); /*extern pascal LongWord TEGetText(Word, Ref, Long, Word, Ref, Handle) inline(0x0C22,dispatcher);extern pascal void TESetText(Word, Ref, Long, Word, Ref, Handle) inline(0x0B22,dispatcher);*/ DisposeHandle (elyssa); MoveCapo(); Update(); SetControls(); return 1;}/* Show's a stdfile dialog for choosing a file to load. Returns 0 if no file chosen, 1 otherwise. */Word DoOpen (void){ Handle elyssa; Pointer emily; SFGetFile2 (125, 50, 0, (Ref) "\pTuning to load", (WordProcPtr) 0, &TypeList, &MyReplyRec); if (MyReplyRec.good) return OpenIt (&SFpath.bufString); else return 0;}int DoSave (void){Handle elyssa;Pointer emily;Handle TextH;int len;int i; extern GSString32 DefaultOut; SFPutFile2 (100, 50, 0, (Ref) "\pSave Tuning As:", 0, (Ref) &DefaultOut, &MyReplyRec); if (MyReplyRec.good) { DestroyOS.pathname = &SFpath.bufString; DestroyGS (&DestroyOS); CreateOS.pathname = &SFpath.bufString; CreateGS (&CreateOS); if (_toolErr) { AlertWindow (4, NULL, CreatErr); return 0; } OpenOS.pathname = CreateOS.pathname; OpenOS.requestAccess = writeEnable; OpenGS (&OpenOS); if (_toolErr) { AlertWindow (4, NULL, OpenErr); return 0; } RWOS.refNum = CloseOS.refNum = OpenOS.refNum; TextH = NewHandle (1, MyID, attrNoSpec, 0); if (_toolErr) { AlertWindow (4, NULL, MemErr); CloseGS (&CloseOS); return 0; } len = TEGetText (5 + 8, (Ref) TextH, 0, 0, (Ref) 0, (Handle) GetCtlHandleFromID (NULL, kCommentField)); if (_toolErr) { len = 0; } elyssa = NewHandle (20 + (strcount << 1), MyID, attrNoSpec | attrFixed | attrLocked, 0); if (_toolErr) { AlertWindow (4, NULL, MemErr); DisposeHandle (TextH); CloseGS (&CloseOS); return 0; } emily = *elyssa; ((InOutRecPtr)emily)->ByteOrder = 0x1234; ((InOutRecPtr)emily)->Version = 1; ((InOutRecPtr)emily)->Capo = Capo; ((InOutRecPtr)emily)->__reserved[0] = 0; ((InOutRecPtr)emily)->__reserved[1] = 0; ((InOutRecPtr)emily)->__reserved[2] = 0; ((InOutRecPtr)emily)->__reserved[3] = 0; ((InOutRecPtr)emily)->__reserved[4] = 0; ((InOutRecPtr)emily)->StrCount = strcount; for (i = 0; i < strcount; i++) ((InOutRecPtr)emily)->Strings[i] = stringsSTD[i]; /* Now I cleverly set the comment length.... */ ((InOutRecPtr)emily)->Strings[i] = len; RWOS.dataBuffer = emily; RWOS.requestCount = 20 + (strcount << 1); WriteGS (&RWOS); if (_toolErr) { AlertWindow (4, NULL, WriteErr); DisposeHandle (TextH); DisposeHandle (elyssa); CloseGS(&CloseOS); return 0; } if (len) { HLock (TextH); RWOS.dataBuffer = *TextH; RWOS.requestCount = len; WriteGS (&RWOS); if (_toolErr) { AlertWindow (4, NULL, WriteErr); DisposeHandle (TextH); DisposeHandle (elyssa); CloseGS (&CloseOS); return 0; } } CloseGS (&CloseOS); DisposeHandle (elyssa); DisposeHandle (TextH); return 1; } return 0;}