home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Utilities / ACDPlay / src / V1.5 / PanelCommands.c < prev    next >
C/C++ Source or Header  |  1997-12-02  |  9KB  |  396 lines

  1. /* PanelCommands.c */
  2.  
  3. #include "Constants.h"
  4.  
  5. #include <exec/types.h>
  6. #include <exec/memory.h>
  7. #include <exec/libraries.h>
  8. #include <intuition/intuition.h>
  9. #include <intuition/intuitionbase.h>
  10. #include <intuition/gadgetclass.h>
  11. #include <libraries/gadtools.h>
  12. #include <libraries/commodities.h>
  13. #include <libraries/asl.h>
  14. #include <graphics/rastport.h>
  15. #include <devices/scsidisk.h>
  16. #include <devices/cd.h>
  17. #include <libraries/screennotify.h>
  18. #include <pragma/screennotify_lib.h>
  19. #include "AsmLib/CD-ROM.h"
  20. #include "Locale.h"
  21. #include "Structures/Application.h"
  22. #include "Structures/DirNode.h"
  23. #include "Structures/MyPubScreenNode.h"
  24. #include "Structures/CDTitleNode.h"
  25.  
  26. #include <clib/alib_protos.h>
  27. #include <clib/dos_protos.h>
  28. #include <clib/exec_protos.h>
  29. #include <clib/asl_protos.h>
  30. #include <clib/gadtools_protos.h>
  31. #include <clib/graphics_protos.h>
  32. #include <clib/intuition_protos.h>
  33. #include <clib/commodities_protos.h>
  34. #include <clib/icon_protos.h>
  35. #include <clib/locale_protos.h>
  36. #include <clib/wb_protos.h>
  37. #include <string.h>
  38. #include <stdlib.h>
  39. #include <stdio.h>
  40. #include <math.h>
  41. #include "ACDPlay_protos.h"
  42.  
  43. ULONG DirectChoice(Application *app, UWORD track)
  44. {
  45.     ULONG suc = RETURN_OK;
  46.     register struct CDStruct *cdstr = app->cdstr;
  47.  
  48.     switch (cdstr->playmode)
  49.     {
  50.         case PLAYMODE_CD:
  51.             switch (cdstr->active)
  52.             {
  53.                 case AUDIO_STAT_PLAYING:
  54.                 case AUDIO_STAT_STOPPED:
  55.                 case AUDIO_STAT_PAUSED:
  56.                     suc = CDPlayA(cdstr->cdx, track, 1);
  57.  
  58.                     if (cdstr->active == AUDIO_STAT_PAUSED)
  59.                         suc |= CDPauseA(cdstr->cdx, TRUE);
  60.                     break;
  61.             }
  62.             break;
  63.  
  64.         case PLAYMODE_RNDCD:
  65.             switch (cdstr->active)
  66.             {
  67.                 case AUDIO_STAT_PLAYING:
  68.                 case AUDIO_STAT_PAUSED:
  69.                 case AUDIO_STAT_STOPPED:
  70.                     suc = CDPlayA(cdstr->cdx, GetRandomTrack(app), 1);
  71.  
  72.                     if (cdstr->active == AUDIO_STAT_PAUSED)
  73.                         suc |= CDPauseA(cdstr->cdx, TRUE);
  74.                     break;
  75.             }
  76.  
  77.         case PLAYMODE_PRG:
  78.         case PLAYMODE_RNDPRG:
  79.             switch (cdstr->active)
  80.             {
  81.                 case AUDIO_STAT_STOPPED:
  82.                     ProgramStart(app);
  83.                     break;
  84.                 case AUDIO_STAT_PLAYING:
  85.                 case AUDIO_STAT_PAUSED:
  86.                     ProgramNext(app);
  87.  
  88.                     if (cdstr->active == AUDIO_STAT_PAUSED)
  89.                         suc = CDPauseA(cdstr->cdx, TRUE);
  90.                     break;
  91.             }
  92.             break;
  93.     }
  94.     cdstr->useraction = TRUE;
  95.  
  96.     CDUpdateA(cdstr->cdx);
  97.     UpdateGadgets(app);
  98.  
  99.     return(suc ? RETURN_SCSIERR : RETURN_OK);
  100. }
  101.  
  102. ULONG EjectButton(Application *app)
  103. {
  104.     ULONG suc;
  105.  
  106.     /* Gibt es eine Möglichkeit, ein und denselben Button zum Öffnen */
  107.     /* und Schließen des Laufwerks zu Verwenden? Ich sehe keine. :-( */
  108.  
  109.     /* Mann müsste auslesen können ob die Schublade offen ist.    */
  110.     /* Ich glaube aus diesem Grund sperrt auch OptyPlayer die     */
  111.     /* manuelle Bedienung der Schublade. Frag doch mal Patrick ob */
  112.     /* er da was machen kann [mak]                                  */
  113.  
  114.     /* Hab' ich schon... :-) */
  115.  
  116.     /* Endlich! Es funfunktioniert! :) */
  117.  
  118.     StopButton(app);
  119.  
  120.     /* Wenn (CD vorhanden ist) oder (Schublade gerade geschlossen wurde) : öffnen */
  121.     if (!CDTestUnitA(app->cdstr->cdx) || (app->cdstr->cdx->cdx_Flags & SPECIALF_JUSTCLOSED))
  122.         suc = CDEjectA(app->cdstr->cdx, TRUE);
  123.     else
  124.         suc = CDEjectA(app->cdstr->cdx, FALSE);
  125.  
  126.     return(suc ? RETURN_SCSIERR : RETURN_OK);
  127. }
  128.  
  129. ULONG JumpBackwardButton(Application *app)
  130. {
  131.     ULONG suc = RETURN_OK;
  132.     register struct CDStruct *cdstr = app->cdstr;
  133.  
  134.     switch (cdstr->playmode)
  135.     {
  136.         case PLAYMODE_CD:
  137.             switch (cdstr->active)
  138.             {
  139.                 case AUDIO_STAT_STOPPED:
  140.                 case AUDIO_STAT_PLAYING:
  141.                 case AUDIO_STAT_PAUSED:
  142.                     suc = CDPrevA(cdstr->cdx);
  143.  
  144.                     if (cdstr->active == AUDIO_STAT_PAUSED)
  145.                         suc |= CDPauseA(cdstr->cdx, TRUE);
  146.                     break;
  147.             }
  148.             break;
  149.  
  150.         case PLAYMODE_RNDCD:
  151.             switch (cdstr->active)
  152.             {
  153.                 case AUDIO_STAT_PLAYING:
  154.                 case AUDIO_STAT_PAUSED:
  155.                     suc = CDPlayA(cdstr->cdx, GetRandomTrack(app), 1);
  156.  
  157.                     if (cdstr->active == AUDIO_STAT_PAUSED)
  158.                         suc |= CDPauseA(cdstr->cdx, TRUE);
  159.                     break;
  160.             }
  161.  
  162.         case PLAYMODE_PRG:
  163.         case PLAYMODE_RNDPRG:
  164.             switch (cdstr->active)
  165.             {
  166.                 case AUDIO_STAT_STOPPED:
  167.                 case AUDIO_STAT_PLAYING:
  168.                 case AUDIO_STAT_PAUSED:
  169.                     ProgramPrev(app);
  170.  
  171.                     if (cdstr->active == AUDIO_STAT_PAUSED)
  172.                         suc = CDPauseA(cdstr->cdx, TRUE);
  173.                     break;
  174.             }
  175.             break;
  176.     }
  177.  
  178.     cdstr->useraction = TRUE;
  179.  
  180.     return(suc ? RETURN_SCSIERR : RETURN_OK);
  181. }
  182.  
  183. ULONG JumpForwardButton(Application *app)
  184. {
  185.     ULONG suc = RETURN_OK;
  186.     register struct CDStruct *cdstr = app->cdstr;
  187.  
  188.     switch (cdstr->playmode)
  189.     {
  190.         case PLAYMODE_CD:
  191.             switch (cdstr->active)
  192.             {
  193.                 case AUDIO_STAT_STOPPED:
  194.                 case AUDIO_STAT_PLAYING:
  195.                 case AUDIO_STAT_PAUSED:
  196.                     if ((cdstr->repeatmode == REPEATMODE_REPALL) && (cdstr->cur_track == cdstr->num_track))
  197.                         suc = CDPlayA(cdstr->cdx, cdstr->cdx->cdx_TOCData->FirstAudioTrack, 1);
  198.                     else
  199.                         suc = CDNextA(cdstr->cdx);
  200.  
  201.                     if (cdstr->active == AUDIO_STAT_PAUSED)
  202.                         suc |= CDPauseA(cdstr->cdx, TRUE);
  203.                     break;
  204.             }
  205.             break;
  206.  
  207.         case PLAYMODE_RNDCD:
  208.             switch (cdstr->active)
  209.             {
  210.                 case AUDIO_STAT_STOPPED:
  211.                 case AUDIO_STAT_PLAYING:
  212.                 case AUDIO_STAT_PAUSED:
  213.                     suc = CDPlayA(cdstr->cdx, GetRandomTrack(app), 1);
  214.  
  215.                     if (cdstr->active == AUDIO_STAT_PAUSED)
  216.                         suc |= CDPauseA(cdstr->cdx, TRUE);
  217.                     break;
  218.             }
  219.  
  220.         case PLAYMODE_PRG:
  221.         case PLAYMODE_RNDPRG:
  222.             switch (cdstr->active)
  223.             {
  224.                 case AUDIO_STAT_STOPPED:
  225.                     ProgramStart(app);
  226.                     break;
  227.                 case AUDIO_STAT_PLAYING:
  228.                 case AUDIO_STAT_PAUSED:
  229.                     ProgramNext(app);
  230.  
  231.                     if (cdstr->active == AUDIO_STAT_PAUSED)
  232.                         suc |= CDPauseA(cdstr->cdx, TRUE);
  233.                     break;
  234.             }
  235.             break;
  236.     }
  237.     cdstr->useraction = TRUE;
  238.  
  239.     return(suc ? RETURN_SCSIERR : RETURN_OK);
  240. }
  241.  
  242. ULONG SearchBackwardButton(Application *app, WORD val)
  243. {
  244.     ULONG suc;
  245.     register struct CDxRequest *cdx = app->cdstr->cdx;
  246.  
  247.     /* Was bringt das eigentlich? */
  248.  
  249.     /* Der Compiler wird gezwungen die Variable in einem Register
  250.        zu halten, was eine Codeersparnis bringt und das Programm
  251.        beschleunigt, außerdem wird damit nicht immer wieder von dem
  252.        Applicationzeiger ausgegangen, wie das sonst oft der Fall ist.
  253.        Allerdings bringt das nur was, wenn das Register nicht anderweitig
  254.        gebraucht wird, und immer zwischengespeichert werden muß. ACDPlay
  255.        wurde damit ca. 2k kürzer. */
  256.  
  257.     switch (app->cdstr->active)
  258.     {
  259.         case AUDIO_STAT_STOPPED:
  260.         case AUDIO_STAT_PLAYING:
  261.         case AUDIO_STAT_PAUSED:
  262.             suc = CDJumpA(cdx, -75 * val, JUMPMODE_PLAY_REL);
  263.             if (app->cdstr->active == AUDIO_STAT_PAUSED)
  264.                 suc |= CDPauseA(cdx, TRUE);
  265.             break;
  266.     }
  267.  
  268.     return(suc ? RETURN_SCSIERR : RETURN_OK);
  269. }
  270.  
  271. ULONG SearchForwardButton(Application *app, WORD val)
  272. {
  273.     ULONG suc;
  274.     register struct CDxRequest *cdx = app->cdstr->cdx;
  275.  
  276.     switch (app->cdstr->active)
  277.     {
  278.         case AUDIO_STAT_STOPPED:
  279.         case AUDIO_STAT_PLAYING:
  280.         case AUDIO_STAT_PAUSED:
  281.             suc = CDJumpA(cdx, 75 * val, JUMPMODE_PLAY_REL);
  282.             if (app->cdstr->active == AUDIO_STAT_PAUSED)
  283.                 suc |= CDPauseA(cdx, TRUE);
  284.             break;
  285.  
  286.     }
  287.  
  288.     return(suc ? RETURN_SCSIERR : RETURN_OK);
  289. }
  290.  
  291. ULONG StopButton(Application *app)
  292. {
  293.     register struct CDStruct *cdstr = app->cdstr;
  294.  
  295.     switch(cdstr->playmode)
  296.     {
  297.         case PLAYMODE_RNDCD:
  298.             InitRandomTracks(cdstr->cdtitles);
  299.             break;
  300.         case PLAYMODE_RNDPRG:
  301.             InitRandomTracks(cdstr->progtitles);
  302.             break;
  303.     }
  304.  
  305.     cdstr->useraction = TRUE;
  306.  
  307.     return(CDStopA(cdstr->cdx) ? RETURN_SCSIERR : RETURN_OK);
  308. }
  309.  
  310. ULONG PauseButton(Application *app)
  311. {
  312.     ULONG suc = RETURN_OK;
  313.     register struct CDxRequest *cdx = app->cdstr->cdx;
  314.  
  315.     switch (app->cdstr->active)
  316.     {
  317.         case AUDIO_STAT_STOPPED:
  318.             if (app->cdstr->playmode != PLAYMODE_PRG)
  319.                 suc = CDPlayA(cdx, cdx->cdx_TOCData->FirstAudioTrack, 1);
  320.         case AUDIO_STAT_PLAYING:
  321.             suc |= CDPauseA(cdx, TRUE);
  322.             break;
  323.         case AUDIO_STAT_PAUSED:
  324.             suc = CDPauseA(cdx, FALSE);
  325.             break;
  326.     }
  327.  
  328.     suc |= CDUpdateA(cdx);    /* Damit der neue AudioStatus gleich übernommen wird */
  329.  
  330.     return(suc ? RETURN_SCSIERR : RETURN_OK);
  331. }
  332.  
  333. ULONG PlayButton(Application *app)
  334. {
  335.     ULONG suc;
  336.     register struct CDxRequest *cdx = app->cdstr->cdx;
  337.  
  338.     switch (app->cdstr->active)
  339.     {
  340.         case AUDIO_STAT_NO_DISK:        /* sollte nicht vorkommen */
  341.             break;
  342.         case AUDIO_STAT_PLAYING:
  343.             suc = CDPlayA(cdx, app->cdstr->cur_track, 1);
  344.             break;
  345.         case AUDIO_STAT_STOPPED:
  346.             switch (app->cdstr->playmode)
  347.             {
  348.                 case PLAYMODE_CD:
  349.                     suc = CDPlayA(cdx, cdx->cdx_TOCData->FirstAudioTrack, 1);
  350.                     break;
  351.                 case PLAYMODE_PRG:
  352.                 case PLAYMODE_RNDPRG:
  353.                     ProgramStart(app);
  354.                     break;
  355.                 case PLAYMODE_RNDCD:
  356.                     suc = CDPlayA(cdx, GetRandomTrack(app), 1);
  357.                     break;
  358.             }
  359.             break;
  360.         case AUDIO_STAT_PAUSED:
  361.             suc = CDPauseA(cdx, FALSE);
  362.             break;
  363.     }
  364.  
  365.     app->cdstr->useraction = TRUE;
  366.  
  367.     return(suc ? RETURN_SCSIERR : RETURN_OK);
  368. }
  369.  
  370. ULONG Trackslider(Application *app, UWORD newpos)
  371. {
  372.     ULONG suc;
  373.     register struct CDxRequest *cdx = app->cdstr->cdx;
  374.  
  375.     /* Bug: Wenn im Pausemodus bis an den Start zurückgescrollt und dann auf Play gedrückt wird,
  376.     ist man an der Stelle, an der man vorher war (nur im Pausemodus).
  377.     Dies kann verhindert werden, indem man _immer_ "newpos + 1" nimmt, dann kann man aber nicht
  378.     ganz bis an den Start zurückgehen.
  379.     Wenn man immer "newpos" nimmt, stimmt die Position nicht mit dem gewünschten Wert überein */
  380.  
  381.     suc = CDUpdateA(cdx);
  382.  
  383.     switch (app->cdstr->active)
  384.     {
  385.         case AUDIO_STAT_PLAYING:
  386.         case AUDIO_STAT_PAUSED:
  387.             suc |= CDJumpA(cdx, (cdx->cdx_TrackLength / 100 * (newpos?newpos+1:0)) - cdx->cdx_CurrentRelAddr, JUMPMODE_PLAY_REL);
  388.             if (app->cdstr->active == AUDIO_STAT_PAUSED)
  389.                 suc |= CDPauseA(cdx, TRUE);
  390.             suc |= CDUpdateA(cdx);
  391.             UpdateTimeGadget(app);
  392.             break;
  393.     }
  394.  
  395.     return(suc ? RETURN_SCSIERR : RETURN_OK);
  396. }