home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga MA Magazine 1998 #6
/
amigamamagazinepolishissue1998.iso
/
cdrom
/
cybersound
/
cdplayer
/
source
/
wbinterface.c
< prev
Wrap
C/C++ Source or Header
|
1977-12-31
|
12KB
|
515 lines
/********************************************
* CD Audio Player using 14bit sound driver *
* for Toshiba 4101 CDRom and compatible *
* (c) 1995 by Christian Buchner *
********************************************
*
* WBInterface.c
*/
/* Note: TAB SIZE = 4 */
/* Includes */
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/icon.h>
#include <libraries/dos.h>
#include <utility/tagitem.h>
#include <gadgets/tapedeck.h>
#include <intuition/gadgetclass.h>
#include <intuition/screens.h>
#include <intuition/icclass.h>
#include <workbench/startup.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
/* Prototypes */
#include "CDPlayer_Protos.h"
void GUI(void);
extern void __saveds ProgramCallback(void);
extern BOOL ReadDefaults(void);
extern void FreeDefaults(void);
BOOL OpenLibs(void);
void CloseLibs(void);
void ReadIcon(void);
void FreeIcon(void);
void CheckString(UBYTE *Name, UBYTE **Storage);
void CheckLong(UBYTE *Name, ULONG **Pointer, ULONG *Storage);
void CheckBoolean(UBYTE *Name, ULONG *Storage);
struct ArgArray
{
ULONG **aa_Tracks;
UBYTE *aa_SCSIName;
ULONG *aa_SCSIUnit;
UBYTE *aa_SoundDriver;
ULONG aa_Repeat;
ULONG *aa_Frequency;
ULONG *aa_Quality;
ULONG *aa_Buffers;
ULONG aa_HighPri;
UBYTE *aa_PubScreen;
ULONG aa_GUI;
};
/* Externals */
extern struct DosLibrary *DOSBase; /* From CDPlayer.c */
extern struct IntuitionBase *IntuitionBase;
extern struct GfxBase *GfxBase;
extern struct Process *MyProc; /* From CLIInterface.c */
extern struct ArgArray AA;
extern UBYTE LineBuffer[256];
extern UBYTE ErrorBuffer[100];
extern struct RDArgs *RDArgs;
extern struct RDArgs *RDArgsSuccess;
/* Default parameters */
extern UBYTE DefaultDriverName[]; /* From CLIInterface.c */
extern UBYTE DefaultSCSIName[];
extern ULONG DefaultSCSIUnit;
extern ULONG DefaultFrequency;
extern ULONG DefaultQuality;
extern ULONG DefaultBuffers;
/* Variables */
struct WBStartup *WBenchMsg;
struct Library *TapeDeckBase;
struct Library *IconBase;
struct DiskObject *DiskObject;
ULONG TT_SCSIUnit;
ULONG TT_Frequency;
ULONG TT_Buffers;
ULONG TT_Quality;
UBYTE Titlebuffer[40];
BOOL LibsOpen;
/*******************************************************************************/
/* Workbench interface routine */
void WBInterface(void)
{
WaitPort(&MyProc->pr_MsgPort);
WBenchMsg=(struct WBStartup*)GetMsg(&MyProc->pr_MsgPort);
/* Open DOS library */
if (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37))
{
/* Open other libraries */
if (OpenLibs())
{
/* Read global defaults */
if (ReadDefaults())
{
/* Read the tooltypes from the icon */
ReadIcon();
/* Set defaults for the arguments */
if (!AA.aa_SCSIName) AA.aa_SCSIName= DefaultSCSIName;
if (!AA.aa_SCSIUnit) AA.aa_SCSIUnit= &DefaultSCSIUnit;
if (!AA.aa_SoundDriver) AA.aa_SoundDriver= DefaultDriverName;
if (!AA.aa_Frequency) AA.aa_Frequency= &DefaultFrequency;
if (!AA.aa_Quality) AA.aa_Quality= &DefaultQuality;
if (!AA.aa_Buffers) AA.aa_Buffers= &DefaultBuffers;
GUI();
FreeIcon();
FreeDefaults();
}
CloseLibs();
}
CloseLibrary((struct Library*)DOSBase);
}
Forbid();
ReplyMsg((struct Message*)WBenchMsg);
}
void GUI(void)
{
BOOL CloseFlag;
struct Screen *Screen;
struct Gadget *tdeck;
struct Window *Window;
ULONG GWidth=201, GHeight=15;
struct IntuiMessage *MyMsg;
ULONG Cl;
UWORD Co;
struct Gadget *IA;
ULONG Mode,OldMode=99;
ULONG Paused,OldPaused=BUT_PLAY;
ULONG track, oldtrack=0;
ULONG position, oldposition=0;
/* Open Libraries */
CloseFlag=OpenLibs();
/* Lock specified public screen */
if (!(Screen=LockPubScreen(AA.aa_PubScreen)))
{
/* or workbench if this failed */
Screen=LockPubScreen(NULL);
}
if (Screen)
{
/* Create TapeDeck gadget */
if (tdeck=NewObject(NULL,"tapedeck.gadget",
TDECK_Tape, TRUE,
GA_Top, Screen->WBorTop+Screen->RastPort.TxHeight+1,
GA_Left, Screen->WBorLeft,
TAG_DONE))
{
/* Setting a custom size currently does not work */
SetAttrs(tdeck,GA_Width, GWidth, TAG_DONE);
SetAttrs(tdeck,GA_Height,GHeight,TAG_DONE);
/* Start with the play button pressed */
SetAttrs(tdeck,TDECK_Mode,BUT_PLAY,TAG_DONE);
/* Open the window */
if (Window=OpenWindowTags(NULL,
WA_Title,"CDPlayer",
WA_DragBar,TRUE,
WA_CloseGadget,TRUE,
WA_DepthGadget,TRUE,
WA_Gadgets,tdeck,
WA_Left,Screen->MouseX-(GWidth+Screen->WBorLeft+Screen->WBorRight)/2,
WA_Top,Screen->MouseY-(GHeight+Screen->WBorTop+Screen->RastPort.TxHeight+1+Screen->WBorBottom)/2,
WA_InnerWidth,GWidth,
WA_InnerHeight,GHeight,
WA_IDCMP,IDCMP_CLOSEWINDOW,
WA_PubScreen, Screen,
TAG_DONE))
{
if (InitDriver(AA.aa_SoundDriver,*AA.aa_Buffers))
{
if (OpenSCSI(AA.aa_SCSIName,*AA.aa_SCSIUnit,(BOOL)AA.aa_HighPri))
{
/* Create a program for replay */
if (!CD_SetProgram(AA.aa_Tracks, ProgramCallback))
{
Message("CD or specified track list contain no audio tracks.");
}
else
{
CD_Frequency(*AA.aa_Frequency);
CD_Quality (*AA.aa_Quality);
/* Start reading/playing */
CD_Start();
/* Note: This uses a delay loop instead of */
/* waiting for signals because the notification */
/* mechanism via icclass doesn't work with */
/* tapedeck.gadget */
while(!CheckSignal(SIGBREAKF_CTRL_C))
{
if (MyMsg=(struct IntuiMessage*)GetMsg(Window->UserPort))
{
/* When we are here we got an IntuiMsg */
Cl=MyMsg->Class;
Co=MyMsg->Code;
IA=(struct Gadget*)MyMsg->IAddress;
ReplyMsg((struct Message*)MyMsg);
/* Window was closed? */
if (Cl==IDCMP_CLOSEWINDOW)
{
break;
}
}
else
{
/* Update track/position */
track=CD_CurrentTrack();
position=CD_CurrentPosition()/75;
if ((track!=oldtrack) || (position!=oldposition))
{
sprintf(Titlebuffer,"CDPlayer %2ld %2ld:%02ld",track,position/60,position%60);
SetWindowTitles(Window,Titlebuffer,(UBYTE*)-1);
oldtrack=track;
oldposition=position;
}
/* Check the play mode */
GetAttr(TDECK_Mode,tdeck,&Mode);
if (Mode!=OldMode)
{
switch(Mode)
{
case BUT_PLAY:
{
CD_Start();
OldMode=Mode;
}
break;
case BUT_STOP:
{
CD_Abort();
CD_ToIndex(CD_CurrentIndex());
OldMode=Mode;
}
break;
case BUT_REWIND:
{
Delay(10);
SetGadgetAttrs(tdeck,Window,NULL,TDECK_Mode,OldMode,TAG_DONE);
if (!CD_PrevIndex())
{
DisplayBeep(NULL);
}
}
break;
case BUT_FORWARD:
{
Delay(10);
SetGadgetAttrs(tdeck,Window,NULL,TDECK_Mode,OldMode,TAG_DONE);
if (!CD_NextIndex())
{
DisplayBeep(NULL);
}
}
break;
}
}
/* Check pause flag */
GetAttr(TDECK_Paused,tdeck,&Paused);
if (Paused!=OldPaused)
{
if (Paused)
{
CD_Pause();
}
else
{
CD_Resume();
}
OldPaused=Paused;
}
/* End of program signalled? */
if (MyProc->pr_Task.tc_SigRecvd & SIGBREAKF_CTRL_F)
{
/* Clear that signal */
SetSignal(0,SIGBREAKF_CTRL_F);
/* Press STOP button */
SetGadgetAttrs(tdeck,Window,NULL,TDECK_Mode,BUT_STOP,TAG_DONE);
}
/* Delay 1/10 of a second */
Delay(5);
}
}
CD_Abort();
}
CloseSCSI();
}
DeInitDriver();
}
CloseWindow(Window);
}
DisposeObject(tdeck);
}
UnlockPubScreen(NULL,Screen);
}
if (CloseFlag) CloseLibs();
}
BOOL OpenLibs(void)
{
BOOL Success=FALSE;
if (!LibsOpen)
{
if (IntuitionBase=(struct IntuitionBase*)OpenLibrary("intuition.library",37))
{
if (GfxBase=(struct GfxBase*)OpenLibrary("graphics.library",37))
{
if (IconBase=OpenLibrary("icon.library",37))
{
if (!(TapeDeckBase=OpenLibrary("gadgets/tapedeck.gadget",39)))
{
Message("Cannot open V39 tapedeck.gadget boopsi class!");
}
else
{
LibsOpen=TRUE;
Success=TRUE;
}
}
}
}
if (!Success)
{
CloseLibs();
}
}
return(Success);
}
void CloseLibs(void)
{
if (TapeDeckBase)
{
CloseLibrary(TapeDeckBase);
TapeDeckBase=NULL;
}
if (IconBase)
{
CloseLibrary(IconBase);
IconBase=NULL;
}
if (GfxBase)
{
CloseLibrary((struct Library*)GfxBase);
GfxBase=NULL;
}
if (IntuitionBase)
{
CloseLibrary((struct Library*)IntuitionBase);
IntuitionBase=NULL;
}
LibsOpen=FALSE;
}
void ReadIcon(void)
{
UBYTE *String;
CurrentDir(WBenchMsg->sm_ArgList->wa_Lock);
if (DiskObject=GetDiskObjectNew(WBenchMsg->sm_ArgList->wa_Name))
{
if (String=FindToolType(DiskObject->do_ToolTypes,"TRACKS"))
{
strncpy(LineBuffer,String,sizeof(LineBuffer)-1);
strcat(LineBuffer,"\n");
if (RDArgs=(struct RDArgs*)AllocDosObject(DOS_RDARGS,TAG_DONE))
{
RDArgs->RDA_Source.CS_Buffer=LineBuffer;
RDArgs->RDA_Source.CS_Length=strlen(LineBuffer);
RDArgs->RDA_Source.CS_CurChr=0;
RDArgs->RDA_DAList=NULL;
RDArgs->RDA_Buffer=NULL;
RDArgs->RDA_BufSiz=NULL;
RDArgs->RDA_ExtHelp=NULL;
RDArgs->RDA_Flags=RDAF_NOPROMPT;
if (!(RDArgsSuccess=ReadArgs("TRACKS/N/M", (LONG *)&AA.aa_Tracks, RDArgs)))
{
Fault(IoErr(),NULL, ErrorBuffer, sizeof(ErrorBuffer));
Message("Error parsing TRACKS tooltype:\n%s\n%s",LineBuffer,ErrorBuffer);
}
}
}
CheckString("DEVICE", &AA.aa_SCSIName);
CheckLong("UNIT", &AA.aa_SCSIUnit, &TT_SCSIUnit);
CheckString("SOUNDDRIVER", &AA.aa_SoundDriver);
CheckBoolean("REPEAT",&AA.aa_Repeat);
CheckLong("FREQUENCY", &AA.aa_Frequency, &TT_Frequency);
CheckLong("QUALITY", &AA.aa_Quality, &TT_Quality);
CheckLong("BUFFERS", &AA.aa_Buffers, &TT_Buffers);
CheckBoolean("HIGHPRI",&AA.aa_HighPri);
CheckString("PUBSCREEN", &AA.aa_PubScreen);
}
}
void FreeIcon(void)
{
if (RDArgsSuccess)
{
FreeArgs(RDArgsSuccess);
RDArgsSuccess=NULL;
}
if (RDArgs)
{
FreeDosObject(DOS_RDARGS, RDArgs);
RDArgs=NULL;
}
if (DiskObject)
{
FreeDiskObject(DiskObject);
DiskObject=NULL;
}
}
void CheckString(UBYTE *Name, UBYTE **Storage)
{
UBYTE *String;
if (String=FindToolType(DiskObject->do_ToolTypes,Name))
{
*Storage=String;
}
}
void CheckLong(UBYTE *Name, ULONG **Pointer, ULONG *Storage)
{
UBYTE *String;
if (String=FindToolType(DiskObject->do_ToolTypes,Name))
{
*Pointer=Storage;
*Storage=atol(String);
}
}
void CheckBoolean(UBYTE *Name, ULONG *Storage)
{
UBYTE *String;
if (String=FindToolType(DiskObject->do_ToolTypes,Name))
{
if ((strlen(String)==0) ||
MatchToolValue(String,"TRUE") ||
MatchToolValue(String,"YES"))
{
*Storage=TRUE;
}
else
{
if (MatchToolValue(String,"FALSE") ||
MatchToolValue(String,"NO"))
{
*Storage=FALSE;
}
else
{
Message("Illegal parameter for %s tooltype\n"
"Use TRUE/YES, FALSE/NO or nothing.\n",Name);
}
}
}
}