home *** CD-ROM | disk | FTP | other *** search
Text File | 1999-09-16 | 7.9 KB | 348 lines | [TEXT/CWIE] |
- /*
- XL
- ⌐1999, @soft
-
- Description: Simple and NOT COMMENTED plugin for MACAST (BLR).
- Version: 1.1
- Released: 9/16/99
- Compatibility: MACAST 1.0
- Version history:
-
- Date Who Changes
- ------+------+------------------------------------------------------
- 091699 SKA Updated to work with BLR API 1.2 and added an alternative
- display mode.
- 071199 SKA Fixed some bugs to prevent excessive lameness with
- non-default skins.
- 061499 SKA Fixed some bugs with skin compatibility in MACAST.
- 042799 SKA Started the work and ended the work. Wee.
- */
-
- #include "MACAST_BLR.h"
-
- #include <string.h>
-
- // Sorry, I am too lazy to comment all this. Deal with it. =)
- // It's ugly and not practical, but hey, it's an example.
-
- const StringPtr gCopyright = "\p= XL =\rby slava";
-
- const StringPtr gModeNames[] =
- {
- "\pXL",
- "\pXXL",
- };
-
- static UInt16* gArray;
- static UInt16 gArraySize;
- static UInt16 gArrayHeight;
- static float gArrayDivider;
-
- static Rect gDigitsRect[5];
- static Rect gIndicatorsRect[3];
- static GWorldPtr gDigitsWorld = nil;
- static GWorldPtr gIndicatorsWorld = nil;
- static UInt8* gFFTArray;
-
- BLRInfoBlock gPlugInfo =
- {
- BLR_INFOBLOCK_HEADER('exmp','=XL='), // new and easy format to define header of BLRInfoBlock.
- // BLR_INFOBLOCK_HEADER needs two arguments, author and plugin id.
- // They are used to identify your plugin among others, and to store
- // preferences. Please do not use 'exmp' as your author code, use something
- // else instead.
-
- BLRInitialize,
- BLRTerminate,
- BLRGetCopyright,
- BLRRender,
- BLRClick,
- nil, // no idle
- nil, // no error reporter
- nil, // no settings
- nil, // no listener
- BLRGetModes, // ÑÑ NEW for API 1.2: Display modes
- BLRGetModeName, // ÑÑ NEW for API 1.2: Display modes
-
- BLR_INFOBLOCK_FOOTER
- };
-
- short resFile;
-
- OSStatus BLRInitialize(FSSpecPtr fs, Rect inRect, UInt32*)
- {
- resFile = FSpOpenResFile(fs, fsRdPerm);
-
- // ugly setup
- for (short i=0;i<4;i++)
- {
- gDigitsRect[i].left = i * 22 + (inRect.left + 15);
- gDigitsRect[i].right = gDigitsRect[i].left + 22;
- gDigitsRect[i].top = inRect.top + 4;
- gDigitsRect[i].bottom = gDigitsRect[i].top + 40;
- }
-
- gDigitsRect[4] = gDigitsRect[2];
- gDigitsRect[4].right = gDigitsRect[4].left + 3;
- ::OffsetRect(&gDigitsRect[2], 6, 0);
- ::OffsetRect(&gDigitsRect[3], 6, 0);
-
- for (short i=0;i<3;i++)
- {
- gIndicatorsRect[i].right = inRect.right - 10;
- gIndicatorsRect[i].left = gIndicatorsRect[i].right - 16;
- gIndicatorsRect[i].top = i*12 + inRect.top+8;
- gIndicatorsRect[i].bottom = gIndicatorsRect[i].top + 7;
- }
-
- Rect temp;
-
- OSErr err;
-
- PicHandle pict = (PicHandle)::GetResource('PICT', 3478);
- if (pict)
- {
- Rect r;
- ::HLock((Handle)pict);
- r = (*pict)->picFrame;
- ::OffsetRect(&r, -r.left, -r.top);
-
- err = ::NewGWorld(&gDigitsWorld, nil, &r, nil, nil, nil);
-
- CGrafPtr mSavePort;
- GDHandle mSaveDevice;
-
- ::GetGWorld(&mSavePort, &mSaveDevice);
- ::SetGWorld(gDigitsWorld, nil);
- ::LockPixels(::GetGWorldPixMap(gDigitsWorld));
- ::EraseRect(&r);
- ::DrawPicture(pict, &r);
- ::UnlockPixels(::GetGWorldPixMap(gDigitsWorld));
- ::SetGWorld(mSavePort, mSaveDevice);
- ::ReleaseResource((Handle)pict);
- }
-
- // aquire indicators gworld.
- gPlugInfo.ma->GetStatusLights(&gIndicatorsWorld, &temp);
-
- UInt16 size;
- // aquire fft array
- gPlugInfo.ma->GetValues(&gFFTArray, &size);
-
- // well it isn't random. it's an array of values that I use to draw.
- // it's gArray for historical reasons =)
- gArraySize = (inRect.right-inRect.left)/2;
- gArray = (UInt16*)NewPtrClear(sizeof(UInt16) * gArraySize);
-
- gArrayHeight = inRect.bottom - inRect.top - 1;
- if (gArrayHeight <= 80)
- {
- gArrayDivider = 80.0 / gArrayHeight;
- }
- else
- {
- gArrayDivider = 1.0;
- }
- return errBLRNoErr;
- }
-
- OSStatus BLRTerminate(UInt32*)
- {
- if (resFile != -1)
- CloseResFile(resFile);
-
- DisposeGWorld(gDigitsWorld);
- DisposePtr((Ptr)gArray);
-
- gDigitsWorld = nil;
- gArray = nil;
-
- return errBLRNoErr;
- }
-
- OSStatus BLRGetCopyright(StringPtr outCopyright, UInt32*)
- {
- BlockMoveData(&gCopyright[1], &outCopyright[1], gCopyright[0]);
- outCopyright[0] = gCopyright[0];
-
- return errBLRNoErr;
- }
-
- OSStatus BLRRender(GWorldPtr inWorld, Rect inRect, UInt32*)
- {
- // calc values
- short a=4;
- for (short i=0;i<gArraySize;i++,a+=2)
- {
- gArray[i] = gFFTArray[a]/gArrayDivider;
-
- if (gArray[i] > gArrayHeight)
- gArray[i] = gArrayHeight;
- }
-
-
- // render.
- UInt16 min, sec;
- GrafPtr port;
- Rect rect;
- UInt32 timer;
- UInt32 status;
- static short middle = (inRect.bottom-inRect.top)/2 - (inRect.bottom-inRect.top)/4;
-
- gPlugInfo.ma->GetStatus(&timer, &status);
-
- min = timer / 60;
- sec = timer % 60;
-
- CGrafPtr mSavePort;
- GDHandle mSaveDevice;
-
- ::GetGWorld(&mSavePort, &mSaveDevice);
- ::SetGWorld(inWorld, nil);
- ::LockPixels(::GetGWorldPixMap(inWorld));
-
- ::ForeColor(blackColor);
- ::BackColor(whiteColor);
-
- GetPort(&port);
-
- ::LockPixels(::GetGWorldPixMap(gDigitsWorld));
-
- SetRect(&rect, (min/10)*22, 0, (min/10)*22+22, 34);
- ::CopyBits(&((GrafPtr)gDigitsWorld)->portBits, &port->portBits,
- &rect,
- &gDigitsRect[0],
- adMax, nil);
-
- SetRect(&rect, (min%10)*22, 0, (min%10)*22+22, 34);
- ::CopyBits(&((GrafPtr)gDigitsWorld)->portBits, &port->portBits,
- &rect,
- &gDigitsRect[1],
- adMax, nil);
-
- SetRect(&rect, (sec/10)*22, 0, (sec/10)*22+22, 34);
- ::CopyBits(&((GrafPtr)gDigitsWorld)->portBits, &port->portBits,
- &rect,
- &gDigitsRect[2],
- adMax, nil);
-
- SetRect(&rect, (sec%10)*22, 0, (sec%10)*22+22, 34);
- ::CopyBits(&((GrafPtr)gDigitsWorld)->portBits, &port->portBits,
- &rect,
- &gDigitsRect[3],
- adMax, nil);
-
- SetRect(&rect, 220, 0, 223, 34);
- ::CopyBits(&((GrafPtr)gDigitsWorld)->portBits, &port->portBits,
- &rect,
- &gDigitsRect[4],
- adMax, nil);
- ::UnlockPixels(::GetGWorldPixMap(gDigitsWorld));
-
- // let's copy indicators now
- // repeat
- if (status & statRepeat)
- {
- if (status & statRepeat1)
- ::SetRect(&rect, 0, 14, 16, 21);
- else
- ::SetRect(&rect, 0, 7, 16, 14);
- } else
- ::SetRect(&rect, 0, 0, 16, 7);
-
- ::LockPixels(::GetGWorldPixMap(gIndicatorsWorld));
-
- ::CopyBits(&((GrafPtr)gIndicatorsWorld)->portBits, &port->portBits,
- &rect,
- &gIndicatorsRect[0],
- srcCopy, nil);
-
- // sleep
- if (status & statSleep)
- ::SetRect(&rect, 16, 7, 32, 14);
- else
- ::SetRect(&rect, 16, 0, 32, 7);
-
- ::CopyBits(&((GrafPtr)gIndicatorsWorld)->portBits, &port->portBits,
- &rect,
- &gIndicatorsRect[1],
- srcCopy, nil);
-
- // random
- if (status & statRandom)
- ::SetRect(&rect, 32, 7, 48, 14);
- else
- ::SetRect(&rect, 32, 0, 48, 7);
-
- ::CopyBits(&((GrafPtr)gIndicatorsWorld)->portBits, &port->portBits,
- &rect,
- &gIndicatorsRect[2],
- srcCopy, nil);
- ::UnlockPixels(::GetGWorldPixMap(gIndicatorsWorld));
-
- if (status & statStopped)
- {
- for (short i=0;i<gArraySize;i++)
- gArray[i] = nil;
- }
-
- ::PenMode(adMax);
-
- gPlugInfo.ma->SetStdColors();
-
- // ÑÑ╩NEW for BLR API 1.2: Display modes
- SInt16 curMode = gPlugInfo.ma->GetMode();
-
- if (!curMode) // mode #0 (first, 'xl')
- {
- MoveTo(inRect.left + 2, inRect.bottom - 4);
- for (short i=0;i<gArraySize;i++)
- {
- Line(0, -gArray[i]);
- Move(2, gArray[i]);
- }
- }
- else // mode #1 (second, 'xxl')
- {
- RGBColor darkerColor;
- GetForeColor(&darkerColor);
-
- darkerColor.red = (UInt16) (darkerColor.red >> 1);
- darkerColor.green = (UInt16) (darkerColor.green >> 1);
- darkerColor.blue = (UInt16) (darkerColor.blue >> 1);
- RGBForeColor(&darkerColor);
-
- PenSize(2,1);
- MoveTo(inRect.left + 2, inRect.bottom - 4);
- for (short i=0;i<gArraySize;i++)
- {
- Line(0, -gArray[i]);
- Move(2, gArray[i]);
- }
- }
-
- ::PenNormal();
-
- ::UnlockPixels(::GetGWorldPixMap(inWorld));
- ::SetGWorld(mSavePort, mSaveDevice);
- return errBLRNoErr;
- }
-
- Boolean BLRClick(Point, UInt32*)
- {
- return false;
- }
-
- SInt16 BLRGetModes()
- {
- return 2; // we support 2 modes
- }
-
- // Get mode name for the current mode (we're using a static array with mode names)
- OSStatus BLRGetModeName(SInt16 inMode, StringPtr outName)
- {
- BlockMoveData(&gModeNames[inMode][1], &outName[1], gModeNames[inMode][0]);
- outName[0] = gModeNames[inMode][0];
-
- return errBLRNoErr;
- }