home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / cdrom / cybersound / cdplayer / source / deliinterface.c < prev    next >
C/C++ Source or Header  |  1977-12-31  |  10KB  |  507 lines

  1.  
  2. /********************************************
  3.  * CD Audio Player using 14bit sound driver *
  4.  *   for Toshiba 4101 CDRom and compatible  *
  5.  *      (c) 1995 by Christian Buchner       *
  6.  ********************************************
  7.  *
  8.  * DeliInterface.c
  9.  */
  10.  
  11. /* Note: TAB SIZE = 4 */
  12.  
  13. /* Includes */
  14.  
  15. #include <proto/dos.h>
  16. #include <proto/exec.h>
  17. #include <proto/intuition.h>
  18. #include <libraries/dos.h>
  19. #include <dos/rdargs.h>
  20. #include <utility/tagitem.h>
  21. #include <string.h>
  22. #include "DeliPlayer.h"
  23.  
  24. /* Prototypes */
  25.  
  26. #include "CDPlayer_Protos.h"
  27. void __asm __saveds DeliProcess(void);
  28. ULONG __asm __saveds Check(void);
  29. ULONG __asm __saveds InitPlayer(void);
  30. ULONG __asm __saveds EndPlayer(void);
  31. ULONG __asm __saveds InitSound(void);
  32. ULONG __asm __saveds EndSound(void);
  33. ULONG __asm __saveds StartInt(void);
  34. ULONG __asm __saveds StopInt(void);
  35. ULONG __asm __saveds UserConfig(void);
  36. ULONG __asm __saveds Config(void);
  37. ULONG __asm __saveds NextPatt(void);
  38. ULONG __asm __saveds PrevPatt(void);
  39. ULONG __asm __saveds NextSong(void);
  40. ULONG __asm __saveds PrevSong(void);
  41. ULONG __asm __saveds SubSongTest(void);
  42. ULONG __asm __saveds Faster(void);
  43. ULONG __asm __saveds Slower(void);
  44. ULONG __asm __saveds Volume(void);
  45. ULONG __asm __saveds Balance(void);
  46. extern BOOL ReadDefaults(void);                /* From CLIInterface.c */
  47. extern void FreeDefaults(void);
  48.  
  49.  
  50. /* Externals */
  51.  
  52. extern struct DosLibrary *DOSBase;            /* From CDPlayer.c */
  53. extern struct IntuitionBase *IntuitionBase;
  54.  
  55. extern UBYTE ErrorBuffer[100];                /* From CLIInterface.c */
  56. extern UBYTE *Template;
  57. extern struct ArgArray AA;
  58. extern struct RDArgs *RDArgs;
  59. extern struct RDArgs *RDArgsSuccess;
  60.  
  61.  
  62. /* Default parameters */
  63.  
  64. extern UBYTE DefaultDriverName[];            /* From CLIInterface.c */
  65. extern UBYTE DefaultSCSIName[];
  66. extern ULONG DefaultSCSIUnit;
  67. extern ULONG DefaultFrequency;
  68. extern ULONG DefaultQuality;
  69. extern ULONG DefaultBuffers;
  70.  
  71.  
  72. /* DeliTracker's stuff */
  73.  
  74. struct DeliTrackerGlobals *DeliBase;
  75. struct MsgPort *DeliPort;
  76.  
  77.  
  78. /* Variables */
  79.  
  80. ULONG Frequency;
  81.  
  82.  
  83. /* Copyright and info */
  84.  
  85. UBYTE AboutString[]="CD Player using a 14bit sound driver\n"
  86.                     "for Toshiba 4101 CDRom and compatible\n"
  87.                     "(c) 1995 by Christian Buchner";
  88.  
  89.  
  90. /* Tag list for DeliTracker */
  91.  
  92. struct TagItem PlayerTagArray[]=
  93. {
  94.     DTP_RequestDTVersion,    16,
  95.     DTP_PlayerVersion,        (PLAYER_VERSION<<16)+PLAYER_REVISION,
  96.     DTP_PlayerName,            (ULONG)"CDPlayer",
  97.     DTP_Creator,            (ULONG)AboutString,
  98.     DTP_Description,        (ULONG)"SCSI CD Digital Audio Player",
  99.     DTP_Flags,                PLYF_SONGEND|PLYF_ANYMEM,
  100.     DTP_DeliBase,            (ULONG)&DeliBase,
  101.     DTP_Check2,                (ULONG)&Check,
  102. /*    DTP_Config,                (ULONG)&Config,        */
  103. /*    DTP_UserConfig,            (ULONG)&UserConfig,    */
  104.     DTP_SubSongTest,        (ULONG)&SubSongTest,
  105.     DTP_Process,            (ULONG)&DeliProcess,
  106.     DTP_Priority,            0,
  107.     DTP_StackSize,            4096,
  108.     DTP_MsgPort,            (ULONG)&DeliPort,
  109.     DTP_InitPlayer,            (ULONG)&InitPlayer,
  110.     DTP_EndPlayer,            (ULONG)&EndPlayer,
  111.     DTP_InitSound,            (ULONG)&InitSound,
  112.     DTP_EndSound,            (ULONG)&EndSound,
  113.     DTP_StartInt,            (ULONG)&StartInt,
  114.     DTP_StopInt,            (ULONG)&StopInt,
  115. /*    DTP_Volume,                (ULONG)&Volume,        */
  116. /*    DTP_Balance,            (ULONG)&Balance,    */
  117.     DTP_Faster,                (ULONG)&Faster,
  118.     DTP_Slower,                (ULONG)&Slower,
  119.     DTP_NextPatt,            (ULONG)&NextPatt,
  120.     DTP_PrevPatt,            (ULONG)&PrevPatt,
  121.     DTP_NextSong,            (ULONG)&NextSong,
  122.     DTP_PrevSong,            (ULONG)&PrevSong,
  123.     TAG_DONE
  124. };
  125.  
  126.  
  127.  
  128. /* Variables and data for parsing the options (same as in CLIInterface.c) */
  129.  
  130. UBYTE IDString[]="CD-DA";
  131.  
  132. struct ArgArray
  133. {
  134.     ULONG **aa_Tracks;
  135.     UBYTE *aa_SCSIName;
  136.     ULONG *aa_SCSIUnit;
  137.     UBYTE *aa_SoundDriver;
  138.     ULONG aa_Repeat;
  139.     ULONG *aa_Frequency;
  140.     ULONG *aa_Quality;
  141.     ULONG *aa_Buffers;
  142.     ULONG aa_HighPri;
  143.     UBYTE *aa_PubScreen;
  144.     ULONG aa_GUI;
  145. };
  146.  
  147.  
  148. /****************************************************************************/
  149.  
  150. /* Our player's Process */
  151.  
  152. void __asm __saveds DeliProcess(void)
  153. {
  154.     BOOL ProcActive=TRUE;
  155.     ULONG Signals;
  156.     struct DeliMessage *DeliMessage;
  157.     
  158.     DOSBase=(struct DosLibrary*)DeliBase->DOSBase;
  159.     IntuitionBase=(struct IntuitionBase*)DeliBase->IntuitionBase;
  160.     
  161.     while(ProcActive)
  162.     {
  163.         Signals=Wait(SIGBREAKF_CTRL_C | (1L<<DeliPort->mp_SigBit));
  164.         
  165.         if (Signals & SIGBREAKF_CTRL_C)
  166.         {
  167.             ProcActive=FALSE;
  168.         }
  169.         else
  170.         {
  171.             if (DeliMessage=(struct DeliMessage*)GetMsg(DeliPort))
  172.             {
  173.                 DeliMessage->Result=(DeliMessage->Function)();
  174.                 ReplyMsg((struct Message*)DeliMessage);
  175.             }
  176.         }
  177.     }
  178. }
  179.  
  180.  
  181.  
  182. /****************************************************************************/
  183.  
  184. /* Callback routine for finished program */
  185.  
  186. void __saveds SongendCallback(void)
  187. {
  188.     /* Repeat desired? */
  189.     if (AA.aa_Repeat)
  190.     {
  191.         /* Restart playing */
  192.         CD_Start();
  193.     }
  194.     else
  195.     {
  196.         /* Signal Songend */
  197.         dt_SongEnd();
  198.     }
  199. }
  200.  
  201.  
  202. /****************************************************************************/
  203.  
  204. /* Module check routine */
  205.  
  206. ULONG __asm __saveds Check(void)
  207. {
  208.     if (!strncmp(IDString,DeliBase->ChkData,5)) return(FALSE);
  209.     else return(TRUE);
  210. }
  211.  
  212.  
  213. /****************************************************************************/
  214.  
  215. /* Init player (alloc channels, etc...) */
  216.  
  217. ULONG __asm __saveds InitPlayer(void)
  218. {
  219.     BOOL Error=TRUE;
  220.     
  221.     /* Read global defaults */
  222.     if (ReadDefaults())
  223.     {
  224.         if (RDArgs=(struct RDArgs*)AllocDosObject(DOS_RDARGS,TAG_DONE))
  225.         {
  226.             RDArgs->RDA_Source.CS_Buffer=(UBYTE*)(dt_GetListDataPos(0))+strlen(IDString);
  227.             RDArgs->RDA_Source.CS_Length=dt_GetListDataSize(0)-strlen(IDString);
  228.             RDArgs->RDA_Source.CS_CurChr=0;
  229.             RDArgs->RDA_DAList=NULL;
  230.             RDArgs->RDA_Buffer=NULL;
  231.             RDArgs->RDA_BufSiz=NULL;
  232.             RDArgs->RDA_ExtHelp=NULL;
  233.             RDArgs->RDA_Flags=RDAF_NOPROMPT;
  234.             
  235.             if (!(RDArgsSuccess=ReadArgs(Template, (LONG *)&AA, RDArgs)))
  236.             {
  237.                 Fault(IoErr(),NULL, ErrorBuffer, sizeof(ErrorBuffer));
  238.                 Message("Error parsing options in fake module:\n%s\n%s",RDArgs->RDA_Source.CS_Buffer+1,ErrorBuffer);
  239.             }
  240.             else
  241.             {
  242.                 /* Set defaults for the arguments */
  243.                 if (!AA.aa_SCSIName)     AA.aa_SCSIName=        DefaultSCSIName;
  244.                 if (!AA.aa_SCSIUnit)     AA.aa_SCSIUnit=        &DefaultSCSIUnit;
  245.                 if (!AA.aa_SoundDriver) AA.aa_SoundDriver=    DefaultDriverName;
  246.                 if (!AA.aa_Frequency)    AA.aa_Frequency=    &DefaultFrequency;
  247.                 if (!AA.aa_Quality)        AA.aa_Quality=        &DefaultQuality;
  248.                 if (!AA.aa_Buffers)        AA.aa_Buffers=        &DefaultBuffers;
  249.                 
  250.                 if (InitDriver(AA.aa_SoundDriver,*AA.aa_Buffers))
  251.                 {
  252.                     if (OpenSCSI(AA.aa_SCSIName,*AA.aa_SCSIUnit,(BOOL)AA.aa_HighPri))
  253.                     {
  254.                         /* Create a program for replay */
  255.                         if (!(CD_SetProgram(AA.aa_Tracks, &SongendCallback)))
  256.                         {
  257.                             Message("CD or specified track list contain no audio tracks.");
  258.                         }
  259.                         else
  260.                         {
  261.                             CD_Frequency(Frequency= *AA.aa_Frequency);
  262.                             CD_Quality  (*AA.aa_Quality);   
  263.                             
  264.                             /* Start with first index in program */
  265.                             DeliBase->SndNum=1;
  266.                             
  267.                             Error=FALSE;
  268.                         }
  269.                     }
  270.                 }
  271.             }
  272.         }
  273.     }
  274.     
  275.     if (Error) EndPlayer();
  276.     
  277.     return(Error);
  278. }
  279.  
  280.  
  281. /****************************************************************************/
  282.  
  283. /* Clean up the Player (deallocate, etc..) */
  284.  
  285. ULONG __asm __saveds EndPlayer(void)
  286. {
  287.     CloseSCSI();
  288.     DeInitDriver();
  289.     
  290.     if (RDArgsSuccess)
  291.     {
  292.         FreeArgs(RDArgs);
  293.         RDArgsSuccess=NULL;
  294.     }
  295.     
  296.     if (RDArgs)
  297.     {
  298.         FreeDosObject(DOS_RDARGS,RDArgs);
  299.         RDArgs=NULL;
  300.     }
  301.     
  302.     FreeDefaults();
  303.     
  304.     return(0);
  305. }
  306.  
  307.  
  308. /****************************************************************************/
  309.  
  310. /* Initialize the "Module" */
  311.  
  312. ULONG __asm __saveds InitSound(void)
  313. {
  314.     /* Prepare replay buffers */
  315.     CD_Init();
  316.     
  317.     /* Restart track list */
  318.     CD_ToIndex(DeliBase->SndNum);
  319.     
  320.     return(0);
  321. }
  322.  
  323.  
  324. /****************************************************************************/
  325.  
  326. /* End sound */
  327.  
  328. ULONG __asm __saveds EndSound(void)
  329. {
  330.     /* Abort playing */
  331.     CD_Abort();
  332.     
  333.     return(0);
  334. }
  335.  
  336.  
  337. /****************************************************************************/
  338.  
  339. /* Start sound */
  340.  
  341. ULONG __asm __saveds StartInt(void)
  342. {
  343.     /* Start or resume reading/playing */
  344.     CD_Start();
  345.     CD_Resume();
  346.     
  347.     return(0);
  348. }
  349.  
  350.  
  351. /****************************************************************************/
  352.  
  353. /* Stop sound */
  354.  
  355. ULONG __asm __saveds StopInt(void)
  356. {
  357.     /* Pause playing */
  358.     CD_Pause();
  359.     
  360.     return(0);
  361. }
  362.  
  363.  
  364. /****************************************************************************/
  365.  
  366. /* UserConfig */
  367.  
  368. ULONG __asm __saveds UserConfig(void)
  369. {
  370.     return(0);
  371. }
  372.  
  373.  
  374. /****************************************************************************/
  375.  
  376. /* Config */
  377.  
  378. ULONG __asm __saveds Config(void)
  379. {
  380.     return(0);
  381. }
  382.  
  383.  
  384. /****************************************************************************/
  385.  
  386. /* Next Pattern */
  387.  
  388. ULONG __asm __saveds NextPatt(void)
  389. {
  390.     CD_Skip(10);
  391.     
  392.     return(0);
  393. }
  394.  
  395.  
  396. /****************************************************************************/
  397.  
  398. /* Prev Pattern */
  399.  
  400. ULONG __asm __saveds PrevPatt(void)
  401. {
  402.     CD_Skip(-10);
  403.     
  404.     return(0);
  405. }
  406.  
  407.  
  408. /****************************************************************************/
  409.  
  410. /* Next Song */
  411.  
  412. ULONG __asm __saveds NextSong(void)
  413. {
  414.     BOOL Error=TRUE;
  415.     UWORD Cur;
  416.     
  417.     if (Cur=CD_NextIndex())
  418.     {
  419.         DeliBase->SndNum=Cur;
  420.         Error=FALSE;
  421.     }
  422.     else
  423.     {
  424.         DisplayBeep(NULL);
  425.     }
  426.     
  427.     return(Error);
  428. }
  429.  
  430.  
  431. /****************************************************************************/
  432.  
  433. /* Prev Song */
  434.  
  435. ULONG __asm __saveds PrevSong(void)
  436. {
  437.     BOOL Error=TRUE;
  438.     UWORD Cur;
  439.     
  440.     if (Cur=CD_PrevIndex())
  441.     {
  442.         DeliBase->SndNum=Cur;
  443.         Error=FALSE;
  444.     }
  445.     else
  446.     {
  447.         DisplayBeep(NULL);
  448.     }
  449.     
  450.     return(Error);
  451. }
  452.  
  453.  
  454. /****************************************************************************/
  455.  
  456. /* Sub Song Test */
  457.  
  458. ULONG __asm __saveds SubSongTest(void)
  459. {
  460.     /* All Indexes are playable (as long as they stay in range) */
  461.     return(0);
  462. }
  463.  
  464.  
  465. /****************************************************************************/
  466.  
  467. /* Play Faster */
  468.  
  469. ULONG __asm __saveds Faster(void)
  470. {
  471.     Frequency+=100;
  472.     CD_Frequency(Frequency);
  473.     return(0);
  474. }
  475.  
  476.  
  477. /****************************************************************************/
  478.  
  479. /* Slower */
  480.  
  481. ULONG __asm __saveds Slower(void)
  482. {
  483.     Frequency-=100;
  484.     CD_Frequency(Frequency);
  485.     return(0);
  486. }
  487.  
  488.  
  489. /****************************************************************************/
  490.  
  491. /* Volume */
  492.  
  493. ULONG __asm __saveds Volume(void)
  494. {
  495.     return(0);
  496. }
  497.  
  498.  
  499. /****************************************************************************/
  500.  
  501. /* Balance */
  502.  
  503. ULONG __asm __saveds Balance(void)
  504. {
  505.     return(0);
  506. }
  507.