home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / tools / spsx / spsx_s01.lzh / SRC / spsx.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  9.4 KB  |  470 lines

  1. #include <stdio.h>
  2. #include <method\methodSx.h>
  3. #include <sxlib.h>
  4. #include <iocslib.h>
  5. #include "pcm8pp.h"
  6. #include "spsx.h"
  7.  
  8. uchar    *pcPcmData[2];                /* PCMバッファ                             */
  9.  
  10. int        iIsPlaying;                    /* 再生中か? */
  11.  
  12. int        iPlayMode;                    /* 再生種別        PLAY_NORMAL                */
  13.                                     /*                 PLAY_RANDOM                */
  14.  
  15. int    iAddPlayFile( uchar *);
  16. int    iReadSoundList( uchar * );
  17. int    iAddPlayAFile( uchar *,uchar *);
  18.  
  19. remote stPlayList_t    stPlayList;
  20.  
  21. extern int    iPlayTrack;
  22. extern uchar    *pcPlayTitle;
  23.  
  24. extern job_t         jobPcmPlay;
  25. extern job_t        jobPlayCtrl;
  26.  
  27. extern rectImg **pImgRandomButton;            /* ランダムボタン */
  28. extern rectImg **pImgDisRndButton;            /* ランダム取り消しボタン */
  29. extern rectImg **pImgPushRndButton;        /* ランダムボタンを押した状態 */
  30. extern rectImg    **pImgPushDisRndButton;        /* ランダム取り消しボタンを押した状態 */
  31.  
  32. extern rectImg **pImageH[5];        /* イメージボタン配列(通常ボタン)     */
  33. extern rectImg **pImageL[5];        /*          (押されている時) */
  34.  
  35. extern window_t        mainWin;        /* ウインドウ定義 */
  36.     
  37. extern m_picbtn_t    stCtrlButton;
  38.  
  39. extern method_t    mCtrlButton;
  40.  
  41.  
  42. void main(int argc, uchar *argv[])
  43. {
  44.     int program_loop = true;
  45.     int        iResult;
  46.     order_t stOrder;
  47.     int        iPauseFlag;                    /* 一時停止中:1     通常:0                */
  48.     uchar    *pcPtr;
  49.     int        iTaskID;
  50.     handle    hHandle;
  51.     tsevent    tsEv;
  52.     int        i;
  53.     int        iCheck;
  54.     uchar    **ppcPtr;                    /* TRAP#2 のアドレス格納のためのポインタポインタ */
  55.  
  56.     iPauseFlag = 0;
  57.     iIsPlaying = 0;
  58.  
  59.  
  60.     iPlayTrack = 0;
  61.     pcPlayTitle = NULL;
  62.  
  63.     /* PCM8++の常駐検査 */
  64.     iResult = B_SUPER(0);                /* スーパーバイザモードへ */
  65.     ppcPtr = (uchar **)0x88;                /* TRAP#2のアドレス */
  66.     pcPtr = *ppcPtr - 16;                /* TRAP#2 - 16 に "PCM8++"と入っているはず */
  67.     iCheck = memcmp(pcPtr,"PCM8++",6);    
  68.     B_SUPER(iResult);                    /* スーパーバイザモードから抜ける */
  69.  
  70.     if ( iCheck != 0 ) {                /* PCM8++がなければ終了 */
  71.         DMError(1,"PCM8++が常駐してません!");
  72.         exit(1);
  73.     }
  74.  
  75.  
  76.     iTaskID = TSFindOwn();
  77.     if ( iTaskID > 0 ) {
  78.         exit(1);
  79.     }
  80.  
  81.     iResult = iReadResFile();            /* リソースファイルを読み込む */
  82.  
  83.     if ( iResult != 0 ) {
  84.         if (iResult == 1) {
  85.             iCloseResFile();
  86.         }
  87.         exit(1);
  88.     }
  89.  
  90.     ChainMethod( &mainWin, &mCtrlButton );
  91.  
  92.  
  93.     if (OpenWindow(&mainWin, -1)) {
  94.         DMError( 1, "ウインドウを開けません!!" );
  95.         iCloseResFile();
  96.         exit(1);
  97.     }
  98.  
  99.  
  100.     stPlayList.pstPlayList = (stPlayListItem_t *)malloc( sizeof(stPlayListItem_t[100]));
  101.  
  102.     if ( stPlayList.pstPlayList == NULL ) {
  103.         DMError(1,"メモリが確保できません");
  104.         iCloseResFile();
  105.         exit(1);
  106.     }
  107.  
  108.     stPlayList.iMusicCount = 0;
  109.     stPlayList.iPlayCount = 0;
  110.     stPlayList.iPlayingNo = 0;
  111.  
  112.     if ( argc >= 2 ) {
  113.         for ( i = 1; i < argc; i++ ) {
  114.             if ( argv[i][0] != '-' && argv[i][0] != '/' ) {
  115.                 iAddPlayFile( argv[i] );
  116.             }
  117.         }
  118.     }
  119.  
  120.     pcPcmData[0]=(uchar *)malloc(PCM_BUF_SIZE);
  121.     pcPcmData[1]=(uchar *)malloc(PCM_BUF_SIZE);
  122.  
  123.     if (pcPcmData[0]==NULL || pcPcmData[1]==NULL) {
  124.         DMError(1,"メモリが確保できません");
  125.         iCloseResFile();
  126.         exit(1);
  127.     }
  128.  
  129.     srand(time(NULL));
  130.  
  131.     iPlayMode = PLAY_NORMAL;
  132.  
  133.     iIsPlaying = 1;
  134.  
  135.     ChainJob(&jobPlayCtrl);
  136.     SetIntervalJob( &jobPlayCtrl,20 );
  137.  
  138.     while (program_loop) {                /* メインループ */
  139.  
  140.         stOrder.ev = MayIHelpYou();
  141.  
  142.         switch (stOrder.ev) {        /* Q:ユーザーさん、何がしたいのですか? */
  143.             case EV_CLOSEALL:                /*   A:全部閉じて欲しいそうです */
  144.               case EV_CLOSEWIN:                /*   A:あるウインドウを閉じて欲しいそうです */
  145.                 program_loop = false;        /* ウインドウは一つしかないから結局終了 */
  146.             default:
  147.                 if ( stOrder.mth == &mCtrlButton ) {
  148.                     switch (stCtrlButton.pValue) {
  149.  
  150.                         case 1:                    /* 再生・一時停止ボタンの処理 */
  151.  
  152.                             if ( iPauseFlag == 1 ) {            /* 一時停止解除 */
  153.                                 AwakeJob(&jobPlayCtrl);
  154.                                 iPauseFlag = 0;
  155.                             }
  156.                             else if ( iIsPlaying == 1 ) {        /* 一時停止        */
  157.                                 SleepJob(&jobPlayCtrl);
  158.                                 iPauseFlag = 1;
  159.                             }
  160.                             else {
  161.                                 iIsPlaying = 1;
  162.  
  163.                                 ChainJob(&jobPlayCtrl);
  164.                                 SetIntervalJob( &jobPlayCtrl,20 );
  165.                             }
  166.  
  167.                             break;
  168.  
  169.                         case 2:                    /* 停止ボタンの処理 */
  170.                             iPauseFlag = 0;
  171.                             UnchainJob();
  172.  
  173.                             break;
  174.  
  175.                         case 3:
  176.                             if ( iIsPlaying == 1 ) {
  177.                                 if ( stPlayList.iPlayCount < stPlayList.iMusicCount ) {
  178.                                     if ( iPauseFlag == 1 ) {
  179.                                         AwakeJob(&jobPlayCtrl);
  180.                                         iPauseFlag = 0;
  181.                                     }
  182.                                     UnchainAJob( &jobPcmPlay );
  183.                                 }
  184.                             } 
  185.                             else {
  186.                                 if ( iPlayTrack < stPlayList.iMusicCount ) {
  187.                                     stPlayList.iPlayingNo++;
  188.                                     stPlayList.iPlayCount++;
  189.                                     pcPlayTitle = stPlayList.pstPlayList[iPlayTrack].acTitle;
  190.                                     iPlayTrack++;
  191.                                     iDrawTitle();
  192.                                     iDrawTrack();
  193.                                 }
  194.                             }
  195.                             break;
  196.  
  197.                         case 4:
  198.                             if ( iIsPlaying == 1 ) {
  199.                                 if ( stPlayList.iPlayCount >= 2 && iPlayMode == PLAY_NORMAL ) {
  200.                                     stPlayList.iPlayingNo -= 2;
  201.                                     stPlayList.iPlayCount -= 2;
  202.     
  203.                                     if ( iPauseFlag == 1 ) {
  204.                                         AwakeJob(&jobPlayCtrl);
  205.                                         iPauseFlag = 0;
  206.                                     }
  207.                                     UnchainAJob( &jobPcmPlay );
  208.                                 }
  209.                             }
  210.                             else {
  211.                                 if ( iPlayTrack > 2 ) {
  212.                                     stPlayList.iPlayingNo--;
  213.                                     stPlayList.iPlayCount--;
  214.                                     pcPlayTitle = stPlayList.pstPlayList[iPlayTrack-2].acTitle;
  215.                                     iPlayTrack--;
  216.                                     iDrawTitle();
  217.                                     iDrawTrack();
  218.                                 }
  219.                             }
  220.                             break;
  221.  
  222.                         case 5:
  223.                             iPauseFlag = 0;
  224.  
  225.                             if ( iPlayMode == PLAY_NORMAL ) {
  226.                                 UnchainJob();
  227.  
  228.                                 iPlayMode = PLAY_RANDOM;
  229.                                 iDrawTrack();
  230.  
  231.                                 iIsPlaying = 1;
  232.  
  233.                                 ChainJob(&jobPlayCtrl);
  234.                                 SetIntervalJob( &jobPlayCtrl,20 );
  235.                             }
  236.                             else {
  237.  
  238.                                 iPlayMode = PLAY_NORMAL;
  239.                                 iDrawTrack();
  240.  
  241.                                 stPlayList.iPlayCount = stPlayList.iPlayingNo;
  242.  
  243.                             }
  244.  
  245.  
  246.                             break;
  247.  
  248.                         default:
  249.                             break;
  250.                     }
  251.                 }
  252.         }
  253.  
  254.     }
  255.  
  256.     UnchainJob();
  257.  
  258.     free(stPlayList.pstPlayList);
  259.  
  260.     free( pcPcmData[0] );
  261.     free( pcPcmData[1] );
  262.  
  263.     CloseWindow(&mainWin);                /* ウインドウを閉じる */
  264.  
  265.     iCloseResFile();
  266.  
  267.  
  268. }
  269.  
  270. int    iAddPlayFile( uchar *pcFile )
  271. {
  272.     char    acExt[4];
  273.     int        iLen;
  274.     int        iTitleDrawFlag;
  275.  
  276.     if ( stPlayList.iMusicCount == 0 ) {    /* いままで曲が登録されていないとき */
  277.         iTitleDrawFlag = 1;                    /* 登録した曲名を表示する必要がある */
  278.     }
  279.     else {
  280.         iTitleDrawFlag = 0;
  281.     }
  282.     iLen = strlen( pcFile );
  283.     iLen -= 3;
  284.     strcpy( acExt, pcFile + iLen );
  285.  
  286.     if ( SXStrCmp( acExt, "SLT", 3 ) == 0 ) {
  287.         iReadSoundList( pcFile);
  288.     }
  289.     else {
  290.         iAddPlayAFile( pcFile,NULL );
  291.     }
  292.  
  293.     if ( iTitleDrawFlag == 1 && stPlayList.iMusicCount > 0 ) {
  294.         iPlayTrack = 1;
  295.         pcPlayTitle = stPlayList.pstPlayList[0].acTitle;
  296.         iDrawTitle();
  297.     }
  298.  
  299.     iDrawTrack();
  300. }
  301.  
  302. int    iReadSoundList( uchar *pcFile )
  303. {
  304. //    int        iHandle;
  305.  
  306.     uchar    acTemp[256];
  307.  
  308.     uchar    acFileName[256];            /* ファイル名 */
  309.     uchar    acTitle[32];                /* 曲名 */
  310.  
  311.     int        i;
  312.     int        j;
  313.  
  314.     FILE    *pFile;
  315.  
  316.  
  317. //    iHandle = TSOpen( pcFile, _O_RDONLY );
  318.     pFile = fopen( pcFile, "r" );
  319.  
  320.     if ( pFile == NULL ) {    /* オープン失敗の場合 */
  321.  
  322.         DMError(1,"OPEN ERROR!!");
  323.         return 1;
  324.     }
  325.  
  326.     while ( fgets( acTemp, sizeof(acTemp), pFile ) != NULL ) {
  327.         i = 0;
  328.  
  329.         /* ファイル名取得 */
  330.         while( acTemp[i] != '\n' && acTemp[i] != '\t' && acTemp[i] != '\0' ) {
  331.             acFileName[i] = acTemp[i];
  332.             i++;
  333.         }
  334.  
  335.         acFileName[i] = '\0';
  336.  
  337.         while( acTemp[i] == '\t' ) {
  338.             i++;
  339.         }
  340.  
  341.         j = 0;
  342.  
  343.         while( acTemp[i] != '\n' && acTemp[i] != '\0' && j < 30 ) {
  344.             acTitle[j] = acTemp[i];
  345.             j++;
  346.             i++;
  347.         }
  348.         acTitle[j] = '\0';
  349.  
  350.  
  351.         if ( acFileName[0] != '\0' ) {
  352.             if ( j > 0 ) {
  353.                 iAddPlayAFile( acFileName, acTitle );
  354.             }
  355.             else {
  356.                 iAddPlayAFile( acFileName, NULL );
  357.             }
  358.         }
  359.     }
  360.  
  361.     fclose( pFile );
  362.  
  363. //    TSClose( iHandle );
  364. }
  365.  
  366.  
  367. int    iAddPlayAFile( uchar *pcFile, uchar *pcTitle )
  368. {
  369.     int        iAddPoint;
  370.     uchar    *pcPtr;
  371.     int        iType;
  372.     uchar    acExt[4];
  373.     int        iLen;
  374.  
  375.     iAddPoint = stPlayList.iMusicCount;
  376.  
  377.     if ( iAddPoint >= 99 ) {
  378.         DMError( 1,"これ以上登録できません!");
  379.         return -1;
  380.     }
  381.  
  382.     iLen = strlen( pcFile );
  383.     iLen -= 3;
  384.     strcpy( acExt, pcFile + iLen );
  385.  
  386.     iType = 0;
  387.  
  388.     if (SXStrCmp( acExt, "S44", 3 ) == 0 ) {
  389.         iType = TYPE_S44;
  390.     }
  391.  
  392.     if ( iType != 0 ) {
  393.         stPlayList.iMusicCount++;
  394.  
  395.         stPlayList.pstPlayList[iAddPoint].iPlayFlag = 0;
  396.         stPlayList.pstPlayList[iAddPoint].iFileType = iType;
  397.  
  398.         strcpy(stPlayList.pstPlayList[iAddPoint].acFileName, pcFile);
  399.  
  400.         if ( pcTitle == NULL ) {
  401.             pcPtr = stPlayList.pstPlayList[iAddPoint].acTitle;
  402.             *pcPtr = (uchar)iFileName2Title( pcFile, pcPtr+1);
  403.         }
  404.         else {
  405.             pcPtr = stPlayList.pstPlayList[iAddPoint].acTitle;
  406.             *pcPtr = (uchar)strlen(pcTitle);
  407.             strcpy(pcPtr+1,pcTitle);
  408.         }        
  409.     }
  410. }
  411.  
  412. int    iFileDrop()
  413. {
  414.     uchar    acFile[256];
  415.     int        iRet;
  416.  
  417.     iRet = ULGetDroppedFile( acFile );
  418.  
  419.     TSEndDrag(0);
  420.  
  421.     if ( iRet > 0 ) {
  422.         iAddPlayFile(acFile);
  423.     }
  424.  
  425.     return 0;
  426. }
  427.  
  428. int    iFileName2Title( uchar    *pcFileName, uchar *pcTitle )
  429. {
  430.     uchar    *pcPtr;
  431.     int        iLen;
  432.     int        i;
  433.     int        iExtPoint;
  434.     int        iCutSize;
  435.  
  436.     iLen = strlen(pcFileName);
  437.     pcPtr = pcFileName;
  438.  
  439.  
  440.     iCutSize = 0;
  441.     iExtPoint = 0;
  442.  
  443.     for ( i = 0; i < iLen; i++ ) {
  444.         if ( (pcPtr[i] > 0x80 && pcPtr[i] < 0x9f) ||
  445.              (pcPtr[i] > 0xe0 && pcPtr[i] < 0xff) ) {
  446.             i++;
  447.         }
  448.         else {
  449.             if (pcPtr[i] == '\\' || pcPtr[i] == '/' || pcPtr[i] == ':' ) {
  450.                 iCutSize = i+1;
  451.             }
  452.             if (pcPtr[i] == '.') {
  453.                 iExtPoint = i;
  454.             }
  455.         }
  456.     }
  457.  
  458.     if ( iExtPoint < iCutSize ) {
  459.         iExtPoint = iLen;
  460.     }
  461.  
  462.  
  463.     for ( i = iCutSize; i < iExtPoint; i++ ) {
  464.         pcTitle[i-iCutSize] = pcPtr[i];
  465.     }
  466.  
  467.     pcTitle[i-iCutSize] = '\0';
  468.  
  469.     return (i - iCutSize);
  470. }