home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga Shareware Floppies / ma58.dms / ma58.adf / superplay-lib_DEV / Programmers / Example_Tools / SampleListDemo / SLD.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-27  |  7.7 KB  |  259 lines

  1. /* ======================================================================== */
  2. /* = Programmname    : SampleListDemo V2.1                      = */
  3. /* =                                      = */
  4. /* ======================================================================== */
  5. /* = Author/Copyright : (c) 1994 by Andreas Ralph Kleinert.               = */
  6. /* =               Freeware. All rights reserved.              = */
  7. /* =                                      = */
  8. /* =                   Use it as an example for programming               = */
  9. /* =                   superplay.library !                                = */
  10. /* =                                      = */
  11. /* ======================================================================== */
  12. /* = Function          : SPObject operations :                             = */
  13. /* =                Test SampleList functions.                        = */
  14. /* ======================================================================== */
  15. /* = Last Update      : 18.7.1994                      = */
  16. /* =                                      = */
  17. /* ======================================================================== */
  18. /* = Remarks          : Needs "asl.library" V37+                          = */
  19. /* =                and "superplay.library" V2+.                      = */
  20. /* =                                      = */
  21. /* ======================================================================== */
  22. /* = Compiler          : SAS/C V6.51                       = */
  23. /* =                (smakefile)                                       = */
  24. /* ======================================================================== */
  25.  
  26. #include <intuition/intuitionbase.h>
  27.  
  28. #include <superplay/superplay.h>
  29. #include <spobjects/spobjects.h>
  30.  
  31. #include <libraries/asl.h>
  32. #include <workbench/startup.h>
  33. #include <exec/interrupts.h>
  34.  
  35. #include <proto/exec.h>
  36. #include <proto/dos.h>
  37. #include <proto/asl.h>
  38. #include <proto/superplay.h>
  39.  
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43.  
  44.  
  45.    /* Help- and Info- Texts */
  46.  
  47. char entry1_text  [] = "\2331;32;40mSampleListDemo V2.1 \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";
  48. char entry2_text  [] = "Plays Sound Samples and Modules via superplay.library.\n";
  49. char entry3_text  [] = "USAGE : \2330;33;40mSampleListDemo\2330;31;40m [? | -STOP | -REMOVE | <Sample/ModuleFileName>]\n";
  50.  
  51.  
  52. char ver_text [] = "\0$VER: SampleListDemo V2.1 (18.7.94)";
  53.  
  54.  
  55. /* *************************************************** */
  56. /* *                             * */
  57. /* * Error-Messages for Leave() and KF_Message()     * */
  58. /* *                             * */
  59. /* *************************************************** */
  60.  
  61. char asllib_text     [] = "You need \42asl.library\42 V37+ !";
  62. char splib_text     [] = "You need \42superplay.library\42 V2+ !";
  63.  
  64.  
  65. /* *************************************************** */
  66. /* *                             * */
  67. /* * MACROs for Version-Tests                 * */
  68. /* *                             * */
  69. /* *************************************************** */
  70.  
  71. #define LibVer(x) ( ((struct Library *) x)->lib_Version )
  72. #define OS_VER      LibVer(SysBase)
  73.  
  74.  
  75. /* *************************************************** */
  76. /* *                             * */
  77. /* * Function Declarations                 * */
  78. /* *                             * */
  79. /* *************************************************** */
  80.  
  81. void __regargs SP_Examine(char *filename);
  82.  
  83. void __regargs Leave(char *endtext, long code);
  84.  
  85.  
  86.    /* Functions from module "SampleListDemo_Subs.o" : */
  87.  
  88. extern void __stdargs SP_Printf(char *formatstring, ...);
  89.  
  90.  
  91. /* *************************************************** */
  92. /* *                             * */
  93. /* * Additional Base Declarations             * */
  94. /* *                             * */
  95. /* *************************************************** */
  96.  
  97. extern struct ExecBase *SysBase;
  98.  
  99. struct SuperPlayBase *SuperPlayBase = N;
  100. struct Library       *AslBase       = N;
  101.  
  102.  
  103. /* *************************************************** */
  104. /* *                             * */
  105. /* * MAIN                         * */
  106. /* *                             * */
  107. /* *************************************************** */
  108.  
  109. void main(long argc, char **argv)
  110. {
  111.  if(argc==0) exit(0);
  112.  
  113.  if( argc > 2 || (argv[1][0] =='?') )
  114.   {
  115.    SP_Printf("%s%s%s", entry1_text, entry2_text, entry3_text);
  116.  
  117.    Leave(N, 0);
  118.   }
  119.  
  120.  AslBase = (struct Library *) OpenLibrary("asl.library", 37);
  121.  if(!AslBase) Leave(asllib_text, 102);
  122.  
  123.  SuperPlayBase = (struct SuperPlayBase *) OpenLibrary("superplay.library", 2);
  124.  if(!SuperPlayBase) Leave(splib_text, 102);
  125.  
  126.  
  127.  /* Play */
  128.  
  129.  if(argc < 2)
  130.   {
  131.    struct FileRequester     *request;
  132.    struct TagItem __aligned  tags[4];
  133.    char                      namebuffer [256];
  134.  
  135.    namebuffer[0] = (char) 0;
  136.  
  137.    tags[0].ti_Tag  = (Tag)   ASL_Hail;
  138.    tags[0].ti_Data = (ULONG) "Select Sample/Module to play :";
  139.  
  140.    tags[1].ti_Tag  = (Tag)   ASL_OKText;
  141.    tags[1].ti_Data = (ULONG) " Play ";
  142.  
  143.    tags[2].ti_Tag  = (Tag)   ASL_CancelText;
  144.    tags[2].ti_Data = (ULONG) " Quit ";
  145.  
  146.    tags[3].ti_Tag  = (Tag)   TAG_DONE;
  147.    tags[3].ti_Data = (ULONG) N;
  148.  
  149.    request = AllocAslRequest(ASL_FileRequest, N);
  150.    if(request)
  151.     {
  152.      if(AslRequest(request, &tags[0]))
  153.       {
  154.        strcpy(namebuffer, request->rf_Dir);
  155.        if(    (namebuffer[strlen(namebuffer)-1] !=      ':')
  156.            && (namebuffer[strlen(namebuffer)-1] !=      '/')
  157.            && (namebuffer[0]                    != (char) 0) ) strcat(namebuffer, "/");
  158.  
  159.        strcat(namebuffer, request->rf_File);
  160.  
  161.        if(namebuffer[0] != (char) 0) SP_Examine(namebuffer);
  162.       }
  163.  
  164.      FreeAslRequest(request);
  165.     }
  166.   }else SP_Examine(argv[1]);
  167.  
  168.  Leave(N, 0);
  169. }
  170.  
  171.  
  172. /* *************************************************** */
  173. /* *                             * */
  174. /* * LEAVE : Global Exit Function Replacement         * */
  175. /* *                             * */
  176. /* *************************************************** */
  177.  
  178. void __regargs Leave(char *endtext, long code)
  179. {
  180.  if(SuperPlayBase) CloseLibrary((APTR) SuperPlayBase);
  181.  if(AslBase)       CloseLibrary((APTR) AslBase);
  182.  
  183.  if(endtext)       SP_Printf("%s\n", endtext);
  184.  
  185.  exit(code);
  186. }
  187.  
  188. /* *************************************************** */
  189. /* *                             * */
  190. /* * Play-Function                     * */
  191. /* *                             * */
  192. /* *************************************************** */
  193.  
  194. void __regargs SP_Examine(char *filename)
  195. {
  196.  APTR handle;
  197.  ULONG retval = SPERR_NO_ERROR;
  198.  struct SPO_SampleList  *SampleList;
  199.  struct SPO_SampleEntry *entry;
  200.  
  201.  handle = SPL_AllocHandle(N);
  202.  if(handle)
  203.   {
  204.                retval = SPL_InitHandleAsDOS( handle, N);
  205.    if(!retval) retval = SPL_ReadPlayData(    handle, filename);
  206.    if(!retval) retval = SPL_GetSampleList(   handle, &SampleList);
  207.    if(!retval)
  208.     {
  209.      if(SampleList)
  210.       {
  211.        SP_Printf("\n This File contains %ld Entrie(s)\n", SampleList->sl_NumEntries);
  212.  
  213.        for(entry=(APTR) SampleList->sl_EntryList.lh_Head;(entry)&&(entry!=(APTR) &(SampleList->sl_EntryList.lh_Tail));)
  214.         {
  215.          SP_Printf("\n Entry-Version : %ld", entry->se_Version);
  216.  
  217.          switch(entry->se_Type)
  218.           {
  219.            case SE_TYPE_SAMPLE :
  220.             {
  221.              SP_Printf("\n Entry-Type    : SAMPLE"
  222.                        "\n SampleBuffer  : 0x%lx"
  223.                        "\n SampleSize    : %ld Bytes"
  224.                        "\n SampleBits    : %ld"
  225.                        "\n SamplesPerSec : %ld"
  226.                        "\n Volume        : %ld"
  227.                       , entry->se_SampleBuffer
  228.                       , entry->se_SampleSize
  229.                       , entry->se_SampleBits
  230.                       , entry->se_SamplesPerSec
  231.                       , entry->se_Volume
  232.                       );
  233.              break;
  234.             }
  235.            default :
  236.             {
  237.              SP_Printf("\n Entry-Type    : <Unknown> -> skipped");
  238.  
  239.              break;
  240.             }
  241.           }
  242.  
  243.          SP_Printf("\n ----------------------------------");
  244.  
  245.          entry = (struct SPO_SampleEntry *) entry->se_Node.ln_Succ;
  246.         }
  247.  
  248.        SP_Printf("\n");
  249.  
  250.       }else retval = SPERR_ILLEGAL_ACCESS;
  251.     }
  252.   
  253.    SPL_FreeHandle(handle);
  254.  
  255.   }else retval = SPERR_NO_HANDLE;
  256.  
  257.  if(retval) Leave(SPL_GetErrorString(retval), 0);
  258. }
  259.