home *** CD-ROM | disk | FTP | other *** search
- /******************** ***********************/
- //
- // 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 "RDriver.h"
- #include "FileUtils.h"
- #include "IT.h"
-
- #ifdef _MAC_H
- #if defined(powerc) || defined(__powerc)
- enum {
- PlayerPROPlug = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( OSType)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( Ptr)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof( MADMusic*)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof( PPInfoRec*)))
- | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof( MADDriverSettings*)))
- };
-
- ProcInfoType __procinfo = PlayerPROPlug;
- #else
- #include <A4Stuff.h>
- #endif
- #endif
-
- #define LOW(para) ((para) & 15)
- #define HI(para) ((para) >> 4)
-
- Cmd* GetMADCommand( register short PosX, register short TrackIdX, register PatData* tempMusicPat)
- {
- if( PosX < 0) PosX = 0;
- else if( PosX >= tempMusicPat->header.size) PosX = tempMusicPat->header.size -1;
-
- return( & (tempMusicPat->Cmds[ (tempMusicPat->header.size * TrackIdX) + PosX]));
- }
-
- Ptr MADPlugNewPtr( long size, MADDriverSettings* init)
- {
- if( init->sysMemory) return NewPtrSys( size);
- else return NewPtr( size);
- }
-
- Ptr MADPlugNewPtrClear( long size, MADDriverSettings* init)
- {
- if( init->sysMemory) return NewPtrSysClear( size);
- else return NewPtrClear( size);
- }
-
- void mystrcpy( Ptr a, Ptr b)
- {
- BlockMove( b + 1, a, b[ 0]);
- }
-
- Boolean compMem( Ptr a, Ptr b, long s)
- {
- long i;
-
- for( i = 0; i < s; i++)
- {
- if( a[ i] != b[ i]) return false;
- }
-
- return true;
- }
-
- void ConvertITEffect( Byte B0, Byte B1, Byte *Cmd, Byte *Arg)
- {
- Byte LoB1 = LOW( B1);
- Byte HiB1 = HI( B1);
-
- switch( B0 + 0x40)
- {
- default: *Cmd = 0; *Arg = 0; break;
- // Speed
- case 'A': *Cmd = speedE; *Arg = B1; break;
- // Tempo
- case 'T': *Cmd = speedE; *Arg = B1; break;
-
- case 'B': *Cmd = fastskipE; *Arg = B1; break;
-
- case 'C': *Cmd = skipE; *Arg = B1; break;
-
- case 'D':
- if( LoB1 == 0 || HiB1 == 0) // Slide volume
- {
- *Cmd = slidevolE; *Arg = B1;
- }
- else if( HiB1 == 0x0F) // Fine Slide volume DOWN
- {
- *Cmd = extendedE;
- *Arg = 11 << 4;
- *Arg += LoB1;
- }
- else if( LoB1 == 0x0F) // Fine Slide volume UP
- {
- *Cmd = extendedE;
- *Arg = 10 << 4;
- *Arg += HiB1;
- }
- break;
-
- case 'E':
- if( HiB1 == 0x0F) // FineSlide DOWN
- {
- *Cmd = extendedE;
- *Arg = 2 << 4; //not supported
- *Arg += LoB1;
- }
- else if( HiB1 == 0x0E) // ExtraFineSlide DOWN
- {
- *Cmd = 0; *Arg = 0; //not supported
- }
- else // Slide DOWN
- {
- *Cmd = upslideE; *Arg = B1;
- }
- break;
-
- case 'F':
- if( HiB1 == 0x0F) // FineSlide UP
- {
- *Cmd = extendedE;
- *Arg = 1 << 4; //not supported
- *Arg += LoB1;
- }
- else if( HiB1 == 0x0E) // ExtraFineSlide UP
- {
- *Cmd = 0; *Arg = 0; //not supported
- }
- else // Slide UP
- {
- *Cmd = downslideE; *Arg = B1;
- }
- break;
-
- case 'G': *Cmd = portamentoE; *Arg = B1; break;
- case 'H': *Cmd = vibratoE; *Arg = B1; break;
-
- case 'J': *Cmd = arpeggioE; *Arg = B1; break;
- case 'K': *Cmd = vibratoslideE; *Arg = B1; break;
- case 'L': *Cmd = portaslideE; *Arg = B1; break;
- case 'O': *Cmd = offsetE; *Arg = B1; break;
-
- case 'S': // Special Effects
- switch( HiB1)
- {
- default: *Cmd = 0; *Arg = 0; break;
- case 2: *Cmd = extendedE; *Arg = 5 << 4; *Arg += LoB1; break; // FineTune
- case 3: *Cmd = extendedE; *Arg = 4 << 4; *Arg += LoB1; break; // Set Vibrato WaveForm
- case 4: *Cmd = extendedE; *Arg = 7 << 4; *Arg += LoB1; break; // Set Tremolo WaveForm
- case 0xB: *Cmd = extendedE; *Arg = 6 << 4; *Arg += LoB1; break; // Loop pattern
- case 0xC: *Cmd = extendedE; *Arg = 12 << 4; *Arg += LoB1; break; // Cut sample
- case 0xD: *Cmd = extendedE; *Arg = 13 << 4; *Arg += LoB1; break; // Delay sample
- case 0xE: *Cmd = extendedE; *Arg = 14 << 4; *Arg += LoB1; break; // Delay pattern
- }
- break;
- }
- }
-
- void ConvertMADEffect( Byte Cmd, Byte Arg, Byte *B0, Byte *B1)
- {
- *B0 = 0;
- *B1 = 0;
-
- switch( Cmd)
- {
- case speedE: *B0 = 'A' - 0x40; *B1 = Arg; break;
- case fastskipE: *B0 = 'B' - 0x40; *B1 = Arg; break;
- case skipE: *B0 = 'C' - 0x40; *B1 = Arg; break;
- case slidevolE: *B0 = 'D' - 0x40; *B1 = Arg; break;
- case upslideE: *B0 = 'E' - 0x40; *B1 = Arg; break;
- case downslideE: *B0 = 'F' - 0x40; *B1 = Arg; break;
- case portamentoE: *B0 = 'G' - 0x40; *B1 = Arg; break;
- case vibratoE: *B0 = 'H' - 0x40; *B1 = Arg; break;
-
- case arpeggioE: *B0 = 'J' - 0x40; *B1 = Arg; break;
- case vibratoslideE: *B0 = 'K' - 0x40; *B1 = Arg; break;
- case portaslideE: *B0 = 'L' - 0x40; *B1 = Arg; break;
- case offsetE: *B0 = 'O' - 0x40; *B1 = Arg; break;
-
- case extendedE:
- switch( (Arg & 0xF0) >> 4)
- {
- case 1: *B0 = 'F' - 0x40; *B1 = 0xf0 + (Arg & 0x0F); break;
- case 2: *B0 = 'E' - 0x40; *B1 = 0xf0 + (Arg & 0x0F); break;
-
- case 5: *B0 = 'S' - 0x40; *B1 = 0x20 + (Arg & 0x0F); break;
-
- case 4: *B0 = 'S' - 0x40; *B1 = 0x30 + (Arg & 0x0F); break;
- case 7: *B0 = 'S' - 0x40; *B1 = 0x40 + (Arg & 0x0F); break;
- case 6: *B0 = 'S' - 0x40; *B1 = 0xb0 + (Arg & 0x0F); break;
- case 12: *B0 = 'S' - 0x40; *B1 = 0xc0 + (Arg & 0x0F); break;
- case 13: *B0 = 'S' - 0x40; *B1 = 0xd0 + (Arg & 0x0F); break;
- case 14: *B0 = 'S' - 0x40; *B1 = 0xe0 + (Arg & 0x0F); break;
-
- case 11: *B0 = 'D' - 0x40; *B1 = 0xf0 + (Arg & 0x0F); break;
- case 10: *B0 = 'D' - 0x40; *B1 = 0x0f + ((Arg & 0x0F)<<4); break;
- }
- break;
- }
- }
-
- OSErr ConvertIT2Mad( Ptr theIT, long MODSize, MADMusic *theMAD, MADDriverSettings *init)
- {
- long i, x, z, channel, Row;
- Ptr MaxPtr;
- Ptr theInstrument[ 256];
- Byte tempChar, *theITCopy;
- short maxTrack;
- short ITperiod[ 12] = {1712,1616,1524,1440,1356,1280,1208,1140,1076,1016, 960, 907};
-
- /**** Variables pour le MAD ****/
- Cmd *aCmd;
-
- /**** Variables pour le IT ****/
-
- ITForm ITinfo;
- /********************************/
-
- for( i = 0 ; i < 256; i ++)
- {
- theInstrument[ i] = 0L;
- }
-
- /**** Header principal *****/
- theITCopy = (Byte*) theIT;
-
- BlockMove( theITCopy, &ITinfo, sizeof( ITinfo));
- theITCopy += 192;
-
- INT16( &ITinfo.orderNum);
- INT16( &ITinfo.insNum);
- INT16( &ITinfo.smpNum);
- INT16( &ITinfo.patNum);
- INT16( &ITinfo.flags);
- INT16( &ITinfo.cwtv);
- INT16( &ITinfo.cmwt);
-
- // if( ITinfo.cmwt < 0x200) DebugStr("\pOld Ins Format");
-
- /**** Order Num *****/
- ITinfo.orders = (unsigned char *) MADPlugNewPtr( ITinfo.orderNum, init);
- if( ITinfo.orders == 0L) return MADNeedMemory;
- BlockMove( theITCopy, ITinfo.orders, ITinfo.orderNum);
- theITCopy += ITinfo.orderNum;
-
- /**** Ins Num *****/
- ITinfo.parapins = (long *) MADPlugNewPtr( ITinfo.insNum * 4L, init);
- if( ITinfo.parapins == 0L) return MADNeedMemory;
- BlockMove( theITCopy, ITinfo.parapins, ITinfo.insNum * 4L);
- theITCopy += ITinfo.insNum * 4L;
- for( i = 0; i < ITinfo.insNum; i++)
- {
- INT32( &ITinfo.parapins[ i]);
- }
- // if( ITinfo.insNum > 0) DebugStr("\pInsNum");
-
- /**** Samp Num *****/
- ITinfo.parapsamp = (long *) MADPlugNewPtr( ITinfo.smpNum * 4L, init);
- if( ITinfo.parapsamp == 0L) return MADNeedMemory;
- BlockMove( theITCopy, ITinfo.parapsamp, ITinfo.smpNum * 4L);
- theITCopy += ITinfo.smpNum * 4L;
- for( i = 0; i < ITinfo.smpNum; i++)
- {
- INT32( &ITinfo.parapsamp[ i]);
- }
-
- /**** Pat Num *****/
- ITinfo.parappat = (long *) MADPlugNewPtr( ITinfo.patNum * 4L, init);
- if( ITinfo.parappat == 0L) return MADNeedMemory;
- BlockMove( theITCopy, ITinfo.parappat, ITinfo.patNum * 4L);
- theITCopy += ITinfo.patNum * 4L;
- for( i = 0; i < ITinfo.patNum; i++)
- {
- INT32( &ITinfo.parappat[ i]);
- }
-
- if( ITinfo.flags & 4)
- {
- /**** Ins Data ****/
- // if( ITinfo.insNum > 64) ITinfo.insNum = 64;
- ITinfo.insdata = (ITInsForm *) MADPlugNewPtr( sizeof(ITInsForm) * ITinfo.insNum, init);
- if( ITinfo.insdata == 0L) return MADNeedMemory;
- for (i = 0; i < ITinfo.insNum; i++)
- {
- theITCopy = (Byte*) theIT;
- theITCopy += ITinfo.parapins[i];
-
- BlockMove( theITCopy, &ITinfo.insdata[i], sizeof( ITInsForm));
-
- if( !compMem( (Ptr) &ITinfo.insdata[i].ID, "IMPI", 4))
- {
- DisposePtr( (Ptr) ITinfo.orders); DisposePtr( (Ptr) ITinfo.parapins);
- DisposePtr( (Ptr) ITinfo.parappat); DisposePtr( (Ptr) ITinfo.insdata);
- DisposePtr( (Ptr) ITinfo.parapsamp);
-
- return MADIncompatibleFile;
- }
- }
- }
-
- /**** Samp Data ****/
- //if( ITinfo.insNum > 64) ITinfo.insNum = 64;
- ITinfo.sampdata = (ITSampForm *) MADPlugNewPtr( sizeof(ITSampForm) * ITinfo.smpNum, init);
- if( ITinfo.sampdata == 0L) return MADNeedMemory;
- for (i = 0; i < ITinfo.smpNum; i++)
- {
- theITCopy = (Byte*) theIT;
- theITCopy += ITinfo.parapsamp[i];
-
- BlockMove( theITCopy, &ITinfo.sampdata[i], sizeof( ITSampForm));
-
- if( !compMem( (Ptr) &ITinfo.sampdata[i].ID, "IMPS", 4))
- {
- DisposePtr( (Ptr) ITinfo.orders); DisposePtr( (Ptr) ITinfo.parapins);
- DisposePtr( (Ptr) ITinfo.parappat); DisposePtr( (Ptr) ITinfo.insdata);
- DisposePtr( (Ptr) ITinfo.parapsamp); DisposePtr( (Ptr) ITinfo.sampdata);
-
- return MADIncompatibleFile;
- }
-
- INT32( &ITinfo.sampdata[i].length);
- INT32( &ITinfo.sampdata[i].loopBegin);
- INT32( &ITinfo.sampdata[i].loopEnd);
- INT32( &ITinfo.sampdata[i].C5Speed);
- INT32( &ITinfo.sampdata[i].SusLoopBegin);
- INT32( &ITinfo.sampdata[i].SusLoopEnd);
- INT32( &ITinfo.sampdata[i].samplePtr);
- INT16( &ITinfo.sampdata[i].Convert);
-
- if( ITinfo.sampdata[i].length > 0)
- {
- theInstrument[ i] = (Ptr) theIT;
- theInstrument[ i] += ITinfo.sampdata[i].samplePtr;
- }
- else theInstrument[ i] = 0;
- }
-
-
- // ******** Le IT a ÄtÄ lu et analysÄ ***********
- // ******** Copie des informations dans le MAD ***
-
- theMAD->header = (MADSpec*) MADPlugNewPtrClear( sizeof( MADSpec), init);
- if( theMAD->header == 0L) return MADNeedMemory;
-
- theMAD->header->MAD = 'MADI';
- for(i=0; i<32; i++) theMAD->header->name[i] = 0;
- for(i=0; i<28; i++) theMAD->header->name[i] = ITinfo.name[i];
-
- mystrcpy( theMAD->header->infos, (Ptr) "\pConverted by PlayerPRO IT Plug (⌐Antoine ROSSET <rossetantoine@bluewin.ch>)");
-
- theMAD->header->numPat = ITinfo.patNum;
- theMAD->header->numPointers = ITinfo.orderNum;
- theMAD->header->speed = ITinfo.iSpeed;
- theMAD->header->tempo = ITinfo.iTempo;
-
- for(i=0; i<128; i++) theMAD->header->oPointers[ i] = 0;
- for(i=0; i<ITinfo.orderNum; i++)
- {
- theMAD->header->oPointers[ i] = ITinfo.orders[i];
-
- if( theMAD->header->oPointers[ i] < 0 || theMAD->header->oPointers[ i] >= ITinfo.patNum) theMAD->header->oPointers[ i] = 0;
- }
-
- for( i = 0; i < MAXTRACK; i++)
- {
- if( i < 64)
- {
- theMAD->header->chanPan[ i] = ITinfo.chanPan[ i];
- theMAD->header->chanVol[ i] = ITinfo.chanVol[ i];
- }
- else
- {
- if( i % 2 == 0) theMAD->header->chanPan[ i] = MAX_PANNING/4;
- else theMAD->header->chanPan[ i] = MAX_PANNING - MAX_PANNING/4;
-
- theMAD->header->chanVol[ i] = MAX_VOLUME;
- }
- }
- theMAD->header->generalVol = 64;
- theMAD->header->generalSpeed = 80;
- theMAD->header->generalPitch = 80;
-
-
- // ********************
- // ***** INSTRUMENTS *****
- // ********************
-
- theMAD->fid = ( InstrData*) MADPlugNewPtrClear( sizeof( InstrData) * (long) MAXINSTRU, init);
- if( !theMAD->fid) return MADNeedMemory;
-
- theMAD->sample = ( sData**) MADPlugNewPtrClear( sizeof( sData*) * (long) MAXINSTRU * (long) MAXSAMPLE, init);
- if( !theMAD->sample) return MADNeedMemory;
-
- for( i = 0; i < MAXINSTRU; i++) theMAD->fid[ i].firstSample = i * MAXSAMPLE;
-
- for(i = 0 ; i < MAXINSTRU; i++)
- {
- for( x = 0; x < MAXSAMPLE; x++) theMAD->sample[ i*MAXSAMPLE + x] = 0L;
-
- theMAD->fid[i].numSamples = 0;
- }
-
- if( ITinfo.flags & 4) // USE INSTRUMENTS
- {
- short minSamp;
-
- for(i=0; i<ITinfo.insNum; i++)
- {
- InstrData *curIns = &theMAD->fid[ i];
-
- curIns->type = 0;
-
- {
- sData *curData;
- short prevSamp, zz;
-
- // Instrument conversion
-
- curIns->numSamples = 0; //ITinfo.insdata[ i].NoS;
- INT16( &ITinfo.insdata[ i].FadeOut);
-
- for( x = 0; x < 26; x++) curIns->name[ x] = ITinfo.insdata[ i].INSName[ x];
-
- for( x = 0; x < 96; x++) curIns->what[ x] = 0;
-
- minSamp = 200;
- for( x = 0; x < 120; x++)
- {
- if( ITinfo.insdata[ i].keyMap[ x].samp)
- {
- if( ITinfo.insdata[ i].keyMap[ x].samp-1 < minSamp) minSamp = ITinfo.insdata[ i].keyMap[ x].samp-1;
- }
- }
-
- for( x = 0; x < 120; x++)
- {
- if( ITinfo.insdata[ i].keyMap[ x].samp)
- {
- if( ITinfo.insdata[ i].keyMap[ x].note < 96)
- {
- curIns->what[ ITinfo.insdata[ i].keyMap[ x].note] = ITinfo.insdata[ i].keyMap[ x].samp-1 - minSamp;
- }
- }
- }
-
- // Samples conversion
-
- zz = 0;
- prevSamp = -1;
-
- for( zz = 0; zz < 120; zz++)
- {
- if( prevSamp != ITinfo.insdata[ i].keyMap[ zz].samp-1 && ITinfo.insdata[ i].keyMap[ zz].samp != 0)
- {
- prevSamp = ITinfo.insdata[ i].keyMap[ zz].samp-1;
-
- curData = theMAD->sample[ i*MAXSAMPLE + curIns->numSamples] = (sData*) MADPlugNewPtrClear( sizeof( sData), init);
- if( curData == 0L) return MADNeedMemory;
-
- curData->size = ITinfo.sampdata[ prevSamp].length;
-
- if( ITinfo.sampdata[prevSamp].Flag&16)
- {
- curData->loopBeg = ITinfo.sampdata[ prevSamp].loopBegin;
- curData->loopSize = ITinfo.sampdata[ prevSamp].loopEnd - ITinfo.sampdata[ prevSamp].loopBegin;
- }
- else
- {
- curData->loopBeg = 0;
- curData->loopSize = 0;
- }
-
- curData->vol = ITinfo.sampdata[ prevSamp].GvL;
- curData->c2spd = ITinfo.sampdata[ prevSamp].C5Speed;
- curData->loopType = 0;
- curData->amp = 8;
-
- if( ITinfo.sampdata[prevSamp].Flag&2)
- {
- curData->amp = 16;
-
- curData->size *= 2;
- curData->loopBeg *= 2;
- curData->loopSize *= 2;
- }
-
-
- curData->relNote = -12;
- for( z = 0; z < 26; z++) curData->name[ z] = ITinfo.sampdata[ prevSamp].SampName[ z];
-
- curData->data = MADPlugNewPtr( curData->size, init);
- if( curData->data == 0L) return MADNeedMemory;
-
- if( curData->data != 0L)
- {
- BlockMove( theInstrument[ prevSamp], curData->data, curData->size);
-
- if( !(ITinfo.sampdata[ prevSamp].Convert & 1) && curData->amp == 8)
- {
- long temp;
-
- for( temp = 0; temp < curData->size; temp++) *(curData->data + temp) -= 0x80;
- }
-
- if( curData->amp == 16)
- {
- unsigned short *tempShort = (unsigned short*) curData->data;
- long temp;
-
- for( temp = 0; temp < curData->size/2; temp++)
- {
- INT16( &( (tempShort[ temp])));
-
- if( !(ITinfo.sampdata[ prevSamp].Convert & 1)) *(tempShort + temp) -= 0x8000;
- }
- }
- }
- curIns->numSamples++;
- }
- }
- }
- }
- }
- else // USE SAMPLES AS INSTRUMENTS
- {
- for(i=0; i<ITinfo.smpNum; i++)
- {
- InstrData *curIns = &theMAD->fid[ i];
-
- curIns->type = 0;
-
- if( theInstrument[ i] != 0L)
- {
- sData *curData;
-
- curIns->numSamples = 1;
- curIns->volFade = DEFAULT_VOLFADE;
-
- curData = theMAD->sample[ i*MAXSAMPLE + 0] = (sData*) MADPlugNewPtrClear( sizeof( sData), init);
- if( curData == 0L) return MADNeedMemory;
-
- curData->size = ITinfo.sampdata[i].length;
- curData->loopBeg = ITinfo.sampdata[i].loopBegin;
- curData->loopSize = ITinfo.sampdata[i].loopEnd - ITinfo.sampdata[i].loopBegin;
- curData->vol = ITinfo.sampdata[i].GvL;
- curData->c2spd = ITinfo.sampdata[i].C5Speed;
- curData->loopType = 0;
- curData->amp = 8;
-
- if( ITinfo.sampdata[i].Flag&2)
- {
- curData->amp = 16;
-
- curData->size *= 2;
- curData->loopBeg *= 2;
- curData->loopSize *= 2;
- }
-
- curData->relNote = -12;
- for( x = 0; x < 26; x++) curIns->name[x] = ITinfo.sampdata[i].SampName[x];
-
- curData->data = MADPlugNewPtr( curData->size, init);
- if( curData->data == 0L) return MADNeedMemory;
-
- if( curData->data != 0L)
- {
- BlockMove( theInstrument[i], curData->data, curData->size);
-
- if( !(ITinfo.sampdata[i].Convert & 1) && curData->amp == 8)
- {
- long temp;
-
- for( temp = 0; temp < curData->size; temp++) *(curData->data + temp) -= 0x80;
- }
-
- if( curData->amp == 16)
- {
- unsigned short *tempShort = (unsigned short*) curData->data;
- long temp;
-
- for( temp = 0; temp < curData->size/2; temp++)
- {
- INT16( &( (tempShort[ temp])));
-
- if( !(ITinfo.sampdata[ i].Convert & 1)) *(tempShort + temp) -= 0x8000;
- }
- }
- }
- }
- else curIns->numSamples = 0;
- }
- }
- // *********************
- // * Check MaxTrack *
- // *********************
-
- maxTrack = 0;
-
- for( i = 0; i < theMAD->header->numPat ; i++)
- {
- ITPatForm *curITPat;
-
- if( ITinfo.parappat[i])
- {
- curITPat = (ITPatForm*) (theIT + ITinfo.parappat[i]);
-
- INT16( &curITPat->length);
- INT16( &curITPat->row);
-
- if( ITinfo.parappat[i] > 0)
- {
- Ptr curDataPat = curITPat->data;
- char maskvariable = 0, prevmaskvariable[ MAXTRACK];
- Boolean NeedChannelToRead = true;
- short xx;
-
- for( xx = 0; xx < MAXTRACK; xx++) prevmaskvariable[ xx] = 0;
-
- Row = 0;
- while( Row < curITPat->row)
- {
- tempChar = *curDataPat;
- curDataPat++;
-
- if( tempChar == 0) Row++;
- else
- {
- if( NeedChannelToRead)
- {
- // Channel
- channel = (tempChar-1) & 63;
-
- if( channel > maxTrack) maxTrack = channel;
- }
-
- if(tempChar & 128)
- {
- prevmaskvariable[ channel] = maskvariable = *curDataPat;
- curDataPat++;
- }
- else maskvariable = prevmaskvariable[ channel];
-
- // NOTE
- if( maskvariable & 1) curDataPat++;
- if( maskvariable & 2) curDataPat++;
- if( maskvariable & 4) curDataPat++;
- if( maskvariable & 8) curDataPat += 2;
- }
- }
-
- if( curDataPat - curITPat->data != curITPat->length) return MADUnknowErr;
- }
- }
- }
-
- maxTrack += 2;
- maxTrack /= 2;
- maxTrack *= 2;
-
- // ********************
- // ***** TEMPORAIRE ******
- // ********************
-
- theMAD->header->numChn = maxTrack;
-
- for( i = 0; i < MAXPATTERN; i++) theMAD->partition[ i] = 0L;
- for( i = 0; i < theMAD->header->numPat ; i++)
- {
- ITPatForm *curITPat;
-
- if( ITinfo.parappat[i])
- {
- curITPat = (ITPatForm*) (theIT + ITinfo.parappat[i]);
- /*
- curITPat->length = INT16( &curITPat->length);
- curITPat->row = INT16( &curITPat->row);
-
- Deja fait dans la recherche du maxtrack
- */
-
- theMAD->partition[ i] = (PatData*) MADPlugNewPtrClear( sizeof( PatHeader) + theMAD->header->numChn * curITPat->row * sizeof( Cmd), init);
- if( theMAD->partition[ i] == 0L) return MADNeedMemory;
-
- theMAD->partition[ i]->header.size = curITPat->row;
- theMAD->partition[ i]->header.compMode = 'NONE';
-
- for( x = 0; x < 20; x++) theMAD->partition[ i]->header.name[ x] = 0;
-
- MaxPtr = (Ptr) theMAD->partition[ i];
- MaxPtr += sizeof( PatHeader) + theMAD->header->numChn * curITPat->row * sizeof( Cmd);
-
- for( Row = 0; Row < curITPat->row; Row++)
- {
- for(z = 0; z < theMAD->header->numChn; z++)
- {
- aCmd = GetMADCommand( Row, z, theMAD->partition[ i]);
-
- aCmd->note = 0xFF;
- aCmd->ins = 0;
- aCmd->cmd = 0;
- aCmd->arg = 0;
- aCmd->vol = 0xFF;
- }
- }
- }
- else // No Data for this pattern - Clear Pattern
- {
- #define DEFSIZE 10L
-
- theMAD->partition[ i] = (PatData*) MADPlugNewPtrClear( sizeof( PatHeader) + theMAD->header->numChn * DEFSIZE * sizeof( Cmd), init);
- if( theMAD->partition[ i] == 0L) return MADNeedMemory;
-
- theMAD->partition[ i]->header.size = DEFSIZE;
- theMAD->partition[ i]->header.compMode = 'NONE';
-
- MADstrcpy( theMAD->partition[ i]->header.name, "Not used pattern");
-
- for( Row = 0; Row < DEFSIZE; Row++)
- {
- for(z = 0; z < theMAD->header->numChn; z++)
- {
- aCmd = GetMADCommand( Row, z, theMAD->partition[ i]);
-
- aCmd->note = 0xFF;
- aCmd->ins = 0;
- aCmd->cmd = 0;
- aCmd->arg = 0;
- aCmd->vol = 0xFF;
- }
- }
- }
-
- if( ITinfo.parappat[i])
- {
- Ptr curDataPat = curITPat->data;
- char maskvariable = 0, prevmaskvariable[ MAXTRACK];
- Boolean NeedChannelToRead = true;
- short xx;
-
- char lastnote[ MAXTRACK], lastins[ MAXTRACK], lastvol[ MAXTRACK], lastcmd[ MAXTRACK], lasteff[ MAXTRACK];
-
- for( xx = 0; xx < MAXTRACK; xx++) prevmaskvariable[ xx] = 0;
-
- Row = 0;
- while( Row < curITPat->row)
- {
- tempChar = *curDataPat;
- curDataPat++;
-
- if( tempChar == 0) Row++;
- else
- {
- if( NeedChannelToRead)
- {
- // Channel
- channel = (tempChar-1) & 63;
- if( channel >= 0 && channel < theMAD->header->numChn) aCmd = GetMADCommand( Row, channel, theMAD->partition[ i]);
- else
- {
- return MADUnknowErr;
- }
- }
-
- if(tempChar & 128)
- {
- prevmaskvariable[ channel] = maskvariable = *curDataPat;
- curDataPat++;
- }
- else maskvariable = prevmaskvariable[ channel];
-
- // NOTE
- if( maskvariable & 1 || maskvariable & 16)
- {
- char note;
-
- if( maskvariable & 1) note = *curDataPat++;
- else note = lastnote[ channel];
- lastnote[ channel] = note;
-
- if( aCmd != 0L)
- {
- aCmd->note = note;
- if( aCmd->note == 255) aCmd->note = 0xFE;
- else if( aCmd->note < 0 || aCmd->note >= NUMBER_NOTES) aCmd->note = 0xFF;
- }
- }
-
- // INSTRUMENT
- if( maskvariable & 2 || maskvariable & 32)
- {
- char ins;
-
- if( maskvariable & 2) ins = *curDataPat++;
- else ins = lastins[ channel];
- lastins[ channel] = ins;
-
- if( aCmd != 0L) aCmd->ins = ins;
- }
-
- // VOLUME
- if( maskvariable & 4 || maskvariable & 64)
- {
- char vol;
-
- if( maskvariable & 4) vol = *curDataPat++;
- else vol = lastvol[ channel];
- lastvol[ channel] = vol;
-
- if( aCmd != 0L)
- {
- aCmd->vol = vol;
- if( aCmd->vol > 64) aCmd->vol = 64;
- aCmd->vol += 0x10;
- }
- }
- else aCmd->vol = 255;
-
- // PARAMETER
- if( maskvariable & 8 || maskvariable & 128)
- {
- char eff, cmd;
-
- if( maskvariable & 8)
- {
- eff = *curDataPat++;
- cmd = *curDataPat++;
- }
- else
- {
- eff = lasteff[ channel];
- cmd = lastcmd[ channel];
- }
- lasteff[ channel] = eff;
- lastcmd[ channel] = cmd;
-
- if( aCmd != 0L)
- {
- ConvertITEffect( eff, cmd, &aCmd->cmd, &aCmd->arg);
- }
- }
- }
- }
-
- if( curDataPat - curITPat->data != curITPat->length) return MADUnknowErr;
- }
- }
-
- DisposePtr( (Ptr) ITinfo.orders); DisposePtr( (Ptr) ITinfo.parapins);
- DisposePtr( (Ptr) ITinfo.parappat); DisposePtr( (Ptr) ITinfo.insdata);
- DisposePtr( (Ptr) ITinfo.parapsamp); DisposePtr( (Ptr) ITinfo.sampdata);
-
- return noErr;
- }
-
- OSErr ExtractITInfo( PPInfoRec *info, Ptr AlienFile)
- {
- short i;
- ITForm ITinfo;
- /********************************/
-
- /**** Header principal *****/
- BlockMove( AlienFile, &ITinfo, 96);
-
- /*** Signature ***/
-
- info->signature = 'IT ';
-
- /*** Internal name ***/
-
- ITinfo.name[ 26] = '\0';
- MADstrcpy( info->internalFileName, ITinfo.name);
-
- /*** Total Patterns ***/
-
- INT16( &ITinfo.patNum);
- info->totalPatterns = ITinfo.patNum;
-
- /*** Partition Length ***/
-
- INT16( &ITinfo.orderNum);
- info->partitionLength = ITinfo.orderNum;
-
- /*** Total Instruments ***/
-
- INT16( &ITinfo.insNum);
- info->totalInstruments = ITinfo.insNum;
-
- /*** Tracks ***/
-
- //info->totalTracks = INT16( &ITinfo.insNum);
-
- MADstrcpy( info->formatDescription, "IT Plug");
-
- return noErr;
- }
-
- OSErr TestITFile( Ptr AlienFile)
- {
- ITForm *myIT = ( ITForm*) AlienFile;
-
- if( compMem( (Ptr) &myIT->ID, "IMPM", 4)) return noErr;
- else return MADFileNotSupportedByThisPlug;
- }
-
- #ifndef _MAC_H
-
- extern "C" EXP OSErr FillPlug( PlugInfo *p);
- extern "C" EXP OSErr mainPLUG( OSType order, Ptr AlienFileName, MADMusic *MadFile, PPInfoRec *info, MADDriverSettings *init);
-
- EXP OSErr FillPlug( PlugInfo *p) // Function USED IN DLL - For PC & BeOS
- {
- MADstrcpy( p->type, ".IT");
- MADstrcpy( p->MenuName, "IT Files");
- p->mode = 'EXIM';
-
- return noErr;
- }
- #endif
-
- #ifdef _MAC_H
- EXP OSErr main( OSType order, Ptr AlienFileName, MADMusic *MadFile, PPInfoRec *info, MADDriverSettings *init)
- #else
- OSErr mainPLUG( OSType order, Ptr AlienFileName, MADMusic *MadFile, PPInfoRec *info, MADDriverSettings *init)
- #endif
- {
- OSErr myErr;
- Ptr AlienFile;
- long sndSize;
- UNFILE iFileRefI;
-
- #ifdef _MAC_H
- #ifndef powerc
- long oldA4 = SetCurrentA4(); //this call is necessary for strings in 68k code resources
- #endif
- #endif
-
- myErr = noErr;
-
- switch( order)
- {
- case 'IMPL':
- iFileRefI = iFileOpen( AlienFileName);
- if( iFileRefI)
- {
- sndSize = iGetEOF( iFileRefI);
-
- // ** MEMORY Test Start
- AlienFile = MADPlugNewPtr( sndSize * 2L, init);
- if( AlienFile == 0L) myErr = MADNeedMemory;
- // ** MEMORY Test End
-
- else
- {
- DisposePtr( AlienFile);
-
- AlienFile = MADPlugNewPtr( sndSize, init);
- if( AlienFile == 0L) myErr = MADNeedMemory;
- else
- {
- myErr = iRead( sndSize, AlienFile, iFileRefI);
-
- if( myErr == noErr)
- {
- myErr = TestITFile( AlienFile);
- if( myErr == noErr)
- {
- myErr = ConvertIT2Mad( AlienFile, sndSize, MadFile, init);
- }
- }
- }
- DisposePtr( AlienFile); AlienFile = 0L;
- }
- iClose( iFileRefI);
- }
- break;
-
- case 'TEST':
- iFileRefI = iFileOpen( AlienFileName);
- if( iFileRefI)
- {
- sndSize = 1024L;
-
- AlienFile = MADPlugNewPtr( sndSize, init);
- if( AlienFile == 0L) myErr = MADNeedMemory;
- else
- {
- myErr = iRead( sndSize, AlienFile, iFileRefI);
-
- myErr = TestITFile( AlienFile);
-
- DisposePtr( AlienFile); AlienFile = 0L;
- }
- iClose( iFileRefI);
- }
- break;
-
- case 'INFO':
- iFileRefI = iFileOpen( AlienFileName);
- if( iFileRefI)
- {
- info->fileSize = iGetEOF( iFileRefI);
-
- sndSize = 5000L; // Read only 5000 first bytes for optimisation
-
- AlienFile = MADPlugNewPtr( sndSize, init);
- if( AlienFile == 0L) myErr = MADNeedMemory;
- else
- {
- myErr = iRead( sndSize, AlienFile, iFileRefI);
- if( myErr == noErr)
- {
- myErr = TestITFile( AlienFile);
- if( !myErr) myErr = ExtractITInfo( info, AlienFile);
- }
- DisposePtr( AlienFile); AlienFile = 0L;
- }
- iClose( iFileRefI);
- }
- break;
-
- default:
- myErr = MADOrderNotImplemented;
- break;
- }
-
- #ifdef _MAC_H
- #ifndef powerc
- SetA4( oldA4);
- #endif
- #endif
-
- return myErr;
- }