home *** CD-ROM | disk | FTP | other *** search
Wrap
/* ======================================================================== */ /* = Programmname : SimplePlay V1.5 = */ /* = = */ /* ======================================================================== */ /* = Author/Copyright : (c) 1994 by Andreas Ralph Kleinert. = */ /* = Freeware. All rights reserved. = */ /* = = */ /* = Use it as an example for programming = */ /* = superplay.library ! = */ /* = = */ /* ======================================================================== */ /* = Function : SPObject operations : = */ /* = - Play Samples/Modules (all SPObjects) = */ /* ======================================================================== */ /* = Last Update : 8.5.1994 = */ /* = = */ /* ======================================================================== */ /* = Remarks : Needs "asl.library" V37+ = */ /* = and "superplay.library" V2+. = */ /* = = */ /* ======================================================================== */ /* = Compiler : SAS/C V6.51 = */ /* = (smakefile) = */ /* ======================================================================== */ #include <intuition/intuitionbase.h> #include <superplay/superplay.h> #include <libraries/asl.h> #include <workbench/startup.h> #include <exec/interrupts.h> #include <proto/exec.h> #include <proto/dos.h> #include <proto/intuition.h> #include <proto/graphics.h> #include <proto/asl.h> #include <proto/superplay.h> #include <stdio.h> #include <stdlib.h> #include <string.h> /* Help- and Info- Texts */ char entry1_text [] = "\2331;32;40mSimplePlay V1.5 \2330;32;40m\2333;32;40m(FREEWARE)\2330;32;40m\n(c) 1994 by Andreas Ralph Kleinert.\nAndreas R. Kleinert, Grube Hohe Grethe 23, D-57074 Siegen, Germany.\n"; char entry2_text [] = "Plays Sound Samples and Modules via superplay.library.\n"; char entry3_text [] = "USAGE : \2330;33;40mSimplePlay\2330;31;40m [? | -STOP | -REMOVE | <Sample/ModuleFileName>]\n"; char ver_text [] = "\0$VER: SimplePlay V1.5 (8.5.94)"; /* *************************************************** */ /* * * */ /* * Error-Messages for Leave() and KF_Message() * */ /* * * */ /* *************************************************** */ char intuitionlib_text [] = "You need \42intuition.library\42 V37+ !"; char asllib_text [] = "You need \42asl.library\42 V37+ !"; char splib_text [] = "You need \42superplay.library\42 V1+ !"; /* *************************************************** */ /* * * */ /* * MACROs for Version-Tests * */ /* * * */ /* *************************************************** */ #define LibVer(x) ( ((struct Library *) x)->lib_Version ) #define OS_VER LibVer(SysBase) /* *************************************************** */ /* * * */ /* * Function Declarations * */ /* * * */ /* *************************************************** */ void __regargs SP_Play(char *filename); void __regargs SP_Remove(void); void __regargs Leave(char *endtext, long code); /* Functions from module "SimplePlay_Subs.o" : */ extern void __stdargs SP_Printf(char *formatstring, ...); /* *************************************************** */ /* * * */ /* * Additional Base Declarations * */ /* * * */ /* *************************************************** */ extern struct ExecBase *SysBase; struct IntuitionBase *IntuitionBase = N; struct SuperPlayBase *SuperPlayBase = N; struct Library *AslBase = N; /* *************************************************** */ /* * * */ /* * Variables for Port Usage * */ /* * * */ /* *************************************************** */ char portname [] = "SimplePlay.port"; char portname_2 [] = "SimplePlay_2.port"; struct MsgPort *port_1 = N; struct MsgPort *port_2 = N; /* *************************************************** */ /* * * */ /* * Structure-Definitions and Flags * */ /* * * */ /* *************************************************** */ struct SPMessage { struct Message sp_Msg; /* The Message itself */ ULONG sp_Flag; /* (See flag-definitions below) */ APTR sp_Ext; /* Future expansions */ }; #define SPF_REMOVE ((ULONG) 1) #define SPF_STOP ((ULONG) 2) /* #define SPF_CONT ((ULONG) 3) */ /* *************************************************** */ /* * * */ /* * Globally Accessed Data * */ /* * * */ /* *************************************************** */ struct TextAttr __aligned chip topazattr = { (STRPTR) "topaz.font", TOPAZ_EIGHTY, FS_NORMAL, FPF_ROMFONT }; struct SPMessage __aligned our_msg = { { N, N, N, NT_MESSAGE, 0, N }, N, N }; /* *************************************************** */ /* * * */ /* * MAIN * */ /* * * */ /* *************************************************** */ extern struct WBStartup *WBenchMsg; char *wbloadname = N; long wb = FALSE; long __stack = 4096; char *__procname = "SimplePlay V1.5"; long __priority = 1; long __BackGroundIO = TRUE; extern BPTR _Backstdout; void main(long argc, char **argv) { port_1 = FindPort(portname); if(argc==0) { wb = TRUE; if(WBenchMsg->sm_NumArgs>1) wbloadname = WBenchMsg->sm_ArgList[1].wa_Name; } if( argc > 2 || (argv[1][0] =='?') ) { SP_Printf("%s%s%s", entry1_text, entry2_text, entry3_text); Leave(N, 0); } IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 37); if(!IntuitionBase) Leave(intuitionlib_text, 100); AslBase = (struct Library *) OpenLibrary("asl.library", 37); if(!AslBase) Leave(asllib_text, 102); SuperPlayBase = (struct SuperPlayBase *) OpenLibrary("superplay.library", 1); if(!SuperPlayBase) Leave(splib_text, 102); /* Play */ if(argc < 2 && !wbloadname) { struct FileRequester *request; struct TagItem __aligned tags[4]; char namebuffer [256]; namebuffer[0] = (char) 0; tags[0].ti_Tag = (Tag) ASL_Hail; tags[0].ti_Data = (ULONG) "Select Sample/Module to play :"; tags[1].ti_Tag = (Tag) ASL_OKText; tags[1].ti_Data = (ULONG) " Play "; tags[2].ti_Tag = (Tag) ASL_CancelText; tags[2].ti_Data = (ULONG) " Quit "; tags[3].ti_Tag = (Tag) TAG_DONE; tags[3].ti_Data = (ULONG) N; request = AllocAslRequest(ASL_FileRequest, N); if(request) { if(AslRequest(request, &tags[0])) { strcpy(namebuffer, request->rf_Dir); if( (namebuffer[strlen(namebuffer)-1] != ':') && (namebuffer[strlen(namebuffer)-1] != '/') && (namebuffer[0] != (char) 0) ) strcat(namebuffer, "/"); strcat(namebuffer, request->rf_File); if(namebuffer[0] != (char) 0) SP_Play(namebuffer); } FreeAslRequest(request); } }else { if(wbloadname) SP_Play(wbloadname); else { if(argv[1][0]!=(char) '-') SP_Play(argv[1]); else { if(!stricmp(argv[1], "-STOP")) { if(port_1) { port_2 = CreatePort(portname_2, 0); our_msg.sp_Msg.mn_ReplyPort = port_2; our_msg.sp_Msg.mn_Length = sizeof(struct SPMessage); our_msg.sp_Flag = SPF_STOP; our_msg.sp_Ext = N; PutMsg(port_1, (struct Message *) &our_msg); WaitPort(port_2); GetMsg(port_2); RemPort(port_2); } } if(!stricmp(argv[1], "-REMOVE")) SP_Remove(); } } } Leave(N, 0); } /* *************************************************** */ /* * * */ /* * LEAVE : Global Exit Function Replacement * */ /* * * */ /* *************************************************** */ void __regargs Leave(char *endtext, long code) { if(SuperPlayBase) CloseLibrary((APTR) SuperPlayBase); if(AslBase) CloseLibrary((APTR) AslBase); if(IntuitionBase) CloseLibrary((APTR) IntuitionBase); if(endtext) if(!wb) SP_Printf("%s\n", endtext); exit(code); } /* *************************************************** */ /* * * */ /* * Play-Function * */ /* * * */ /* *************************************************** */ void __regargs SP_Play(char *filename) { APTR handle; ULONG retval = SPERR_NO_ERROR; struct SPMessage *got_msg = N; struct MsgPort *our_waitport = N; ULONG run = TRUE, flag; SP_Remove(); our_waitport = CreatePort(portname, 0); if(our_waitport) { handle = SPL_AllocHandle(N); if(handle) { if(!(retval = SPL_InitHandleAsDOS(handle, N))) { if(!(retval = SPL_SuperPlay(handle, filename))) { for(;run;) { WaitPort(our_waitport); got_msg = (APTR) GetMsg(our_waitport); flag = got_msg->sp_Flag; switch(flag) { case SPF_REMOVE : { SPL_FreeHandle(handle); run = FALSE; break; } case SPF_STOP : { SPL_StopReplay(handle); break; } } ReplyMsg((APTR) got_msg); } } } }else retval = SPERR_NO_HANDLE; while( got_msg = (APTR)GetMsg(our_waitport) ) ReplyMsg((APTR)got_msg); RemPort(our_waitport); } if(retval) Leave(SPL_GetErrorString(retval), 0); } /* *************************************************** */ /* * * */ /* * Remove-Function * */ /* * * */ /* *************************************************** */ void __regargs SP_Remove(void) { struct MsgPort *stfr_port = N; port_1 = FindPort(portname); /* still there ? */ if(port_1) /* remove previous song and task, if existant */ { stfr_port = CreatePort(portname_2, 0); if(stfr_port) { our_msg.sp_Msg.mn_ReplyPort = stfr_port; our_msg.sp_Msg.mn_Length = sizeof(struct SPMessage); our_msg.sp_Flag = SPF_REMOVE; our_msg.sp_Ext = N; port_1 = FindPort(portname); /* still there ? */ if(port_1) { PutMsg(port_1, (struct Message *) &our_msg); WaitPort(stfr_port); } while( GetMsg(stfr_port) ) ; RemPort(stfr_port); } } }