home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Dream 59
/
CDDream59.ISO
/
BeOs
/
Sound
/
Intel
/
PPBeDevKit.ZIP
/
PLAYERPR.TAR
/
PlayerPRO
/
Source
/
Mac-PlugImport.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-12-26
|
16KB
|
624 lines
/******************** ***********************/
//
// Player PRO 5.0 - DRIVER SOURCE CODE -
//
// Library Version 5.0
//
// To use with MAD Library for Mac: Symantec, CodeWarrior and MPW
//
// Antoine ROSSET
// 16 Tranchees
// 1206 GENEVA
// SWITZERLAND
//
// COPYRIGHT ANTOINE ROSSET 1996, 1997, 1998
//
// Thank you for your interest in PlayerPRO !
//
// FAX: (+41 22) 346 11 97
// PHONE: (+41 79) 203 74 62
// Internet: RossetAntoine@bluewin.ch
//
/******************** ***********************/
#include "mixedmode.h"
#include "RDriver.h"
#include "RDriverInt.h"
#include "Aliases.h"
#include "FileUtils.h"
#include "Files.h"
#include <string.h>
#define MAXPLUG 40
#define RSRCNAME "\pRsrc Plug Sys##"
void pStrCpy( unsigned char *s1, unsigned char *s2)
{
register short len, i;
if (*s2 <= 220)
{
len = *s2;
for ( i = 0; i <= len; i++)
{
s1[ i] = s2[ i];
}
}
else MyDebugStr( __LINE__, __FILE__, "String to biiig !");
}
Handle MADGet1Resource( OSType type, short id, MADLibrary* init)
{
if( init->sysMemory)
{
Handle tH, dH;
tH = Get1Resource( type, id);
if( tH == 0L) return 0L;
DetachResource( tH);
HNoPurge( tH);
dH = NewHandleSys( GetHandleSize( tH));
if( dH == 0L) MyDebugStr( __LINE__, __FILE__, "");
if( MemError() != noErr) MyDebugStr( __LINE__, __FILE__, "");
HLock( dH);
HLock( tH);
BlockMove( *tH, *dH, GetHandleSize( tH));
HUnlock( dH);
HUnlock( tH);
DisposeHandle( tH);
tH = 0L;
return dH;
}
else
{
Handle dH = Get1Resource( type, id);
if( dH == 0L) return 0L;
DetachResource( dH);
HNoPurge( dH);
return dH;
}
}
typedef OSErr (*MyProcPtr) ( OSType, char*, MADMusic*, PPInfoRec*, MADDriverSettings *);
OSErr CallImportPlug( MADLibrary *inMADDriver,
short PlugNo, // CODE du plug
OSType order,
char *AlienFile,
MADMusic *theNewMAD,
PPInfoRec *info)
{
OSErr myErr;
short fileID;
UniversalProcPtr thecall;
MADDriverSettings driverSettings;
driverSettings.sysMemory = false;
if( inMADDriver->ThePlug[ PlugNo].IOPlug == 0L) return -1;
HLock( inMADDriver->ThePlug[ PlugNo].IOPlug);
if( *inMADDriver->ThePlug[ PlugNo].IOPlug == 0L) return -1;
if( !EqualString( RSRCNAME, inMADDriver->ThePlug[ PlugNo].file.name, false, false))
{
fileID = FSpOpenResFile( &inMADDriver->ThePlug[ PlugNo].file, fsCurPerm);
UseResFile( fileID);
}
#define MyCallMode ( kCStackBased|\
RESULT_SIZE( SIZE_CODE( sizeof(OSErr) ))|\
STACK_ROUTINE_PARAMETER( 1, SIZE_CODE( sizeof( OSType)))|\
STACK_ROUTINE_PARAMETER( 2, SIZE_CODE( sizeof( char*)))|\
STACK_ROUTINE_PARAMETER( 3, SIZE_CODE( sizeof( MADMusic*)))|\
STACK_ROUTINE_PARAMETER( 4, SIZE_CODE( sizeof( PPInfoRec*)))|\
STACK_ROUTINE_PARAMETER( 5, SIZE_CODE( sizeof( MADDriverSettings*))))
#if defined(powerc) || defined (__powerc)
if( inMADDriver->ThePlug[ PlugNo].hasPPCCode)
{
thecall = (UniversalProcPtr) *inMADDriver->ThePlug[ PlugNo].IOPlug;
myErr = CallUniversalProc( thecall, MyCallMode, order, AlienFile, theNewMAD, info, &driverSettings);
}
else
{
thecall = NewRoutineDescriptor( (ProcPtr) *inMADDriver->ThePlug[ PlugNo].IOPlug, MyCallMode, kM68kISA);
myErr = CallUniversalProc( thecall, MyCallMode, order, AlienFile, theNewMAD, info, &driverSettings);
DisposeRoutineDescriptor( thecall);
}
#else
myErr = (* (MyProcPtr) (*inMADDriver->ThePlug[ PlugNo].IOPlug)) ( order, AlienFile, theNewMAD, info, &driverSettings);
#endif
//myErr = TESTmain( order, AlienFile, theNewMAD, info, &driverSettings);
HUnlock( inMADDriver->ThePlug[ PlugNo].IOPlug);
if( !EqualString( RSRCNAME, inMADDriver->ThePlug[ PlugNo].file.name, false, false))
CloseResFile( fileID);
// theNewMAD->currentDriver = 0L;
return( myErr);
}
OSErr PPTestFile( MADLibrary *inMADDriver, char *kindFile, char *AlienFile)
{
short i;
MADMusic aMAD;
PPInfoRec InfoRec;
for( i = 0; i < inMADDriver->TotalPlug; i++)
{
if( !MADstrcmp( kindFile, inMADDriver->ThePlug[ i].type))
{
return( CallImportPlug( inMADDriver, i, 'TEST', AlienFile, &aMAD, &InfoRec));
}
}
return MADCannotFindPlug;
}
OSErr PPMADInfoFile( char *AlienFile, PPInfoRec *InfoRec)
{
MADSpec *theMAD;
long fileSize;
short fileID;
theMAD = (MADSpec*) NewPtr( sizeof( MADSpec) + 200L);
fileID = iFileOpen( AlienFile);
if( !fileID)
{
DisposePtr( (Ptr) theMAD);
return -1;
}
fileSize = iGetEOF( fileID);
iRead( sizeof( MADSpec), (Ptr) theMAD, fileID);
iClose( fileID);
strcpy( InfoRec->internalFileName, theMAD->name);
InfoRec->totalPatterns = theMAD->numPat;
InfoRec->partitionLength = theMAD->numPointers;
InfoRec->totalTracks = theMAD->numChn;
InfoRec->signature = 'MADI';
strcpy( InfoRec->formatDescription, "MADI");
InfoRec->totalInstruments = theMAD->numInstru;
InfoRec->fileSize = fileSize;
DisposePtr( (Ptr) theMAD);
theMAD = 0L;
return noErr;
}
OSErr PPInfoFile( MADLibrary *inMADDriver, char *kindFile, char *AlienFile, PPInfoRec *InfoRec)
{
short i;
MADMusic aMAD;
if( !MADstrcmp( kindFile, "MADI"))
{
PPMADInfoFile( AlienFile, InfoRec);
return noErr;
}
for( i = 0; i < inMADDriver->TotalPlug; i++)
{
if( !MADstrcmp( kindFile, inMADDriver->ThePlug[ i].type))
{
return( CallImportPlug( inMADDriver, i, 'INFO', AlienFile, &aMAD, InfoRec));
}
}
return MADCannotFindPlug;
}
OSErr PPExportFile( MADLibrary *inMADDriver, char *kindFile, char *AlienFile, MADMusic *theNewMAD)
{
short i;
PPInfoRec InfoRec;
for( i = 0; i < inMADDriver->TotalPlug; i++)
{
if( !MADstrcmp( kindFile, inMADDriver->ThePlug[ i].type))
{
return( CallImportPlug( inMADDriver, i, 'EXPL', AlienFile, theNewMAD, &InfoRec));
}
}
return MADCannotFindPlug;
}
OSErr PPImportFile( MADLibrary *inMADDriver, char *kindFile, char *AlienFile, MADMusic **theNewMAD)
{
short i;
PPInfoRec InfoRec;
for( i = 0; i < inMADDriver->TotalPlug; i++)
{
if( !MADstrcmp( kindFile, inMADDriver->ThePlug[ i].type))
{
*theNewMAD = (MADMusic*) MADNewPtrClear( sizeof( MADMusic), inMADDriver);
if( !*theNewMAD) return -1L;
return( CallImportPlug( inMADDriver, i, 'IMPL', AlienFile, *theNewMAD, &InfoRec));
}
}
return MADCannotFindPlug;
}
OSErr CheckMADFile( Ptr name)
{
UNFILE refNum;
char charl[ 10];
OSErr err;
refNum = iFileOpen( name);
if( !refNum) return -1;
else
{
iRead( 10, charl, refNum);
if( charl[ 0] == 'M' && // MADI
charl[ 1] == 'A' &&
charl[ 2] == 'D' &&
charl[ 3] == 'I') err = noErr;
else err = -1;
iClose( refNum);
}
return err;
}
OSErr PPIdentifyFile( MADLibrary *inMADDriver, char *type, char *AlienFile)
{
UNFILE refNum;
short i;
PPInfoRec InfoRec;
OSErr iErr = noErr;
MADstrcpy( type, "!!!!");
// Check if we have access to this file
refNum = iFileOpen( AlienFile);
if( !refNum) return -1;
else
{
if( iGetEOF( refNum) < 100) iErr = -36;
iClose( refNum);
if( iErr) return iErr;
}
// Is it a MAD file?
iErr = CheckMADFile( AlienFile);
if( iErr == noErr)
{
MADstrcpy( type, "MADI");
return noErr;
}
for( i = 0; i < inMADDriver->TotalPlug; i++)
{
if( CallImportPlug( inMADDriver, i, 'TEST', AlienFile, 0L, &InfoRec) == noErr)
{
MADstrcpy( type, inMADDriver->ThePlug[ i].type);
return noErr;
}
}
MADstrcpy( type, "!!!!");
return MADCannotFindPlug;
}
OSType GetPPPlugType( MADLibrary *inMADDriver, short ID, OSType mode)
{
short i, x;
if( ID >= inMADDriver->TotalPlug) MyDebugStr( __LINE__, __FILE__, "PP-Plug ERROR. ");
for( i = 0, x = 0; i < inMADDriver->TotalPlug; i++)
{
if( inMADDriver->ThePlug[ i].mode == mode || inMADDriver->ThePlug[ i].mode == 'EXIM')
{
if( ID == x)
{
short xx;
OSType type;
xx = strlen( inMADDriver->ThePlug[ i].type);
if( xx > 4) xx = 4;
type = ' ';
BlockMove( inMADDriver->ThePlug[ i].type, &type, xx);
return type;
}
x++;
}
}
MyDebugStr( __LINE__, __FILE__, "PP-Plug ERROR II.");
return noErr;
}
Boolean MADPlugAvailable( MADLibrary *inMADDriver, char *kindFile)
{
short i;
if( !MADstrcmp( kindFile, "MADI")) return true;
for( i = 0; i < inMADDriver->TotalPlug; i++)
{
if( !MADstrcmp( kindFile, inMADDriver->ThePlug[ i].type)) return true;
}
return false;
}
void LoadImportPLUG( MADLibrary *inMADDriver, short No, FSSpec *theSpec)
{
Handle theRes;
short fileID;
Str255 tStr;
inMADDriver->ThePlug[ No].file = *theSpec;
fileID = FSpOpenResFile( theSpec, fsCurPerm);
/** CODE du Plug-in **/
#if defined(powerc) || defined (__powerc)
theRes = MADGet1Resource('PPCC', 1000, inMADDriver);
if( theRes != 0L)
{
inMADDriver->ThePlug[ No].hasPPCCode = true;
}
else
{
inMADDriver->ThePlug[ No].hasPPCCode = false;
theRes = MADGet1Resource('CODE', 1000, inMADDriver);
}
if( theRes == 0L) MyDebugStr( __LINE__, __FILE__, "Err Plug");
if( *theRes == 0L) MyDebugStr( __LINE__, __FILE__, "Err Plug Rsrc Second Level");
inMADDriver->ThePlug[ No].IOPlug = theRes;
#else
theRes = MADGet1Resource('CODE', 1000, inMADDriver);
if( theRes == 0L) MyDebugStr( __LINE__, __FILE__, "Err Plug");
if( *theRes == 0L) MyDebugStr( __LINE__, __FILE__, "Err Plug Rsrc Second Level");
inMADDriver->ThePlug[ No].IOPlug = theRes;
#endif
GetIndString( tStr, 1000, 1);
BlockMove( tStr + 1, &inMADDriver->ThePlug[ No].type, 4);
inMADDriver->ThePlug[ No].type[ 4] = 0;
GetIndString( tStr, 1000, 2);
BlockMove( tStr + 1, &inMADDriver->ThePlug[ No].mode, 4);
GetIndString( inMADDriver->ThePlug[ No].MenuName, 1000, 3);
GetIndString( inMADDriver->ThePlug[ No].AuthorString, 1000, 4);
CloseResFile( fileID);
}
void NScanDirImportPlug( MADLibrary *inMADDriver, long dirID, short VRefNum, Str255 Fname)
{
CInfoPBRec info;
Str255 tempStr;
short i;
Boolean targetIsFolder, wasAliased;
FSSpec theSpec;
FInfo fndrInfo;
info.hFileInfo.ioNamePtr = tempStr;
info.hFileInfo.ioVRefNum = VRefNum;
for (i = 1; true; i ++)
{
info.hFileInfo.ioDirID = dirID;
info.hFileInfo.ioFDirIndex = i;
if (PBGetCatInfoSync( &info) != noErr) break;
FSMakeFSSpec( info.hFileInfo.ioVRefNum, dirID, info.hFileInfo.ioNamePtr, &theSpec);
ResolveAliasFile( &theSpec, true, &targetIsFolder, &wasAliased);
FSpGetFInfo( &theSpec, &fndrInfo);
if( targetIsFolder) //if((info.hFileInfo.ioFlAttrib & 16))
{
if( Fname[ 0] > 0)
{
if( EqualString( info.hFileInfo.ioNamePtr, Fname, false, false)) // == true ||
// EqualString( theSpec.name, Fname, false, false) == true)
{
CInfoPBRec ci;
ci.hFileInfo.ioNamePtr = theSpec.name;
ci.hFileInfo.ioVRefNum = theSpec.vRefNum;
ci.hFileInfo.ioDirID = theSpec.parID;
ci.hFileInfo.ioFDirIndex = 0;
PBGetCatInfoSync( &ci);
NScanDirImportPlug( inMADDriver, ci.hFileInfo.ioDirID, ci.hFileInfo.ioVRefNum, Fname);
}
}
}
else if( fndrInfo.fdType == 'IMPL') //if( info.hFileInfo.ioFlFndrInfo.fdType == 'IMPL')
{
// HGetVol( 0L, &vRefNum, &dirIDCopy);
////
// iErr = HSetVol( 0L, theSpec.vRefNum, theSpec.parID);
if( inMADDriver->TotalPlug < MAXPLUG)
{
LoadImportPLUG( inMADDriver, inMADDriver->TotalPlug, &theSpec);
inMADDriver->TotalPlug++;
}
// iErr = HSetVol( 0L, vRefNum, dirIDCopy);
// if( iErr != noErr) MyDebugStr( __LINE__, __FILE__, "HSetVol error...");
}
}
}
/*void InitImportMenu(void)
{
short i;
ImportMenu = GetMenu( 138);
ExportMenu = GetMenu( 139);
for( i = 0; i < inMADDriver->TotalPlug; i++)
{
switch( inMADDriver->ThePlug[ i].mode)
{
case 'EXIM':
AppendMenu( ImportMenu, inMADDriver->ThePlug[ i].MenuName);
AppendMenu( ExportMenu, inMADDriver->ThePlug[ i].MenuName);
break;
case 'EXPL':
AppendMenu( ExportMenu, inMADDriver->ThePlug[ i].MenuName);
break;
case 'IMPL':
AppendMenu( ImportMenu, inMADDriver->ThePlug[ i].MenuName);
break;
}
}
InsertMenu( ImportMenu, hierMenu);
InsertMenu( ExportMenu, hierMenu);
}*/
void NScanResource( MADLibrary *inMADDriver)
{
short i;
#define BASERES 5000
for( i = 0; i < MAXPLUG; i++)
{
Boolean ResourceOK;
Handle aRes, bRes;
ResourceOK = true;
aRes = MADGet1Resource( 'CODE', BASERES + i, inMADDriver);
if( aRes == 0L) ResourceOK = false;
else
{
DisposeHandle( aRes);
aRes = 0L;
}
bRes = MADGet1Resource( 'STR#', BASERES + i, inMADDriver);
if( bRes == 0L) ResourceOK = false;
else
{
DisposeHandle( bRes);
bRes = 0L;
}
if( inMADDriver->TotalPlug < MAXPLUG && ResourceOK == true)
{
short No = inMADDriver->TotalPlug;
Handle theRes;
Str255 tStr;
// theName = LMGetCurApName();
HGetVol( 0L, &inMADDriver->ThePlug[ No].file.vRefNum, &inMADDriver->ThePlug[ No].file.parID);
pStrCpy( inMADDriver->ThePlug[ No].file.name, RSRCNAME);
/** CODE du Plug-in **/
#if defined(powerc) || defined (__powerc)
theRes = MADGet1Resource('PPCC', BASERES+i, inMADDriver);
if( theRes != 0L)
{
inMADDriver->ThePlug[ No].hasPPCCode = true;
}
else
{
inMADDriver->ThePlug[ No].hasPPCCode = false;
theRes = MADGet1Resource('CODE', BASERES+i, inMADDriver);
}
if( theRes == 0L) MyDebugStr( __LINE__, __FILE__, "Err Plug Rsrc");
if( *theRes == 0L) MyDebugStr( __LINE__, __FILE__, "Err Plug Rsrc Second Level");
inMADDriver->ThePlug[ No].IOPlug = theRes;
#else
theRes = MADGet1Resource('CODE', BASERES+i, inMADDriver);
if( theRes == 0L) MyDebugStr( __LINE__, __FILE__, "Err Plug Rsrc");
if( *theRes == 0L) MyDebugStr( __LINE__, __FILE__, "Err Plug Rsrc Second Level");
inMADDriver->ThePlug[ No].IOPlug = theRes;
#endif
GetIndString( tStr, BASERES+i, 1);
BlockMove( tStr + 1, &inMADDriver->ThePlug[ No].type, 4);
inMADDriver->ThePlug[ No].type[ 4] = 0;
GetIndString( tStr, BASERES+i, 2);
BlockMove( tStr + 1, &inMADDriver->ThePlug[ No].mode, 4);
GetIndString( inMADDriver->ThePlug[ No].MenuName, BASERES+i, 3);
GetIndString( inMADDriver->ThePlug[ No].AuthorString, BASERES+i, 4);
inMADDriver->TotalPlug++;
}
}
}
void MInitImportPlug( MADLibrary *inMADDriver, Ptr PlugsFolderName)
{
short vRefNum;
long dirID;
HGetVol( 0L, &vRefNum, &dirID);
inMADDriver->ThePlug = (PlugInfo*) MADNewPtr( MAXPLUG * sizeof( PlugInfo), inMADDriver);
inMADDriver->TotalPlug = 0;
if( PlugsFolderName != 0L)
{
c2pstr( PlugsFolderName);
NScanDirImportPlug( inMADDriver, dirID, vRefNum, (unsigned char*) PlugsFolderName);
p2cstr( (unsigned char*) PlugsFolderName);
}
HSetVol( 0L, vRefNum, dirID);
NScanResource( inMADDriver);
}
void CloseImportPlug( MADLibrary *inMADDriver)
{
short i;
for( i = 0; i < inMADDriver->TotalPlug; i++)
{
if( inMADDriver->ThePlug[ i].IOPlug != 0L)
DisposeHandle( inMADDriver->ThePlug[ i].IOPlug);
inMADDriver->ThePlug[ i].IOPlug = 0L;
}
DisposePtr( (Ptr) inMADDriver->ThePlug); inMADDriver->ThePlug = 0L;
}