home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xmedia.cpp < prev    next >
C/C++ Source or Header  |  1997-04-05  |  8KB  |  381 lines

  1. #define INCL_OS2MM
  2. #define INCL_MMIOOS2
  3. #define INCL_MMIO_CODEC
  4. #define INCL_MCIOS2
  5. #define INCL_MACHDR
  6.  
  7. #include "XVideo.h"
  8. #include "XFrmWnd.h"
  9. #include "XMsgBox.h"
  10. #include "XSound.h"
  11. #include "XCntrEvn.h"
  12.  
  13. #include "os2me.h"
  14. #include "string.h"
  15. #include "stdlib.h"
  16. #include "stdio.h"
  17.  
  18.  
  19. #ifndef WC_GRAPHICBUTTON
  20. #define WC_GRAPHICBUTTON ((PSZ)0xffff0040L)
  21. #endif
  22.  
  23. //defines for sound-class, it can handle *.mid and *.wav
  24. #define MIDI 1
  25. #define WAVE 2
  26.  
  27. ULONG mediaCounter = 0;
  28.  
  29.  
  30. LONG XMediaWindow::SendMCIString(const USHORT notify)
  31. {
  32.     char errorBuffer[CCHMAXPATH];
  33.  
  34.     return mciSendString((PSZ) commandString, (PSZ) errorBuffer, (USHORT) CCHMAXPATH, owner->GetHandle(), notify);
  35. }
  36.  
  37.  
  38. XMediaWindow :: XMediaWindow(const XFrameWindow * res):XObjectWindow(res)
  39. {
  40.     mediaId = ++mediaCounter;
  41.     errorEnabled = FALSE;
  42.     owner = (XFrameWindow *) res;
  43.     commandString = (char *) malloc(CCHMAXPATH + 100);
  44. }
  45.  
  46.  
  47. XMediaWindow :: ~XMediaWindow()
  48. {
  49.     free(commandString);
  50. }
  51.  
  52.  
  53.  
  54. /*@ 
  55. @class XVideo
  56. @parent XMediaWindow
  57. @type overview
  58. @symbol _
  59. */
  60.  
  61.  
  62. /*@ XVideo :: XVideo(const XFrameWindow * ow)
  63. @group constructors/destructors
  64. @remarks Construct a video-window. To use this control you must invoke the multimedia-library!
  65. @parameters XFrameWindow * owner    the owner of the video
  66. */
  67. XVideo :: XVideo(const XFrameWindow * ow):XMediaWindow(ow)
  68. {
  69.     sprintf(idString, "OOL_Movie%u", (unsigned int) mediaId);
  70. }
  71.  
  72.  
  73. /*@ XVideo::CloseDevice(void)
  74. @group open/close
  75. @remarks Close the device
  76. @returns LONG resultcode
  77. */
  78. LONG XVideo::CloseDevice(void)
  79. {
  80.     strcpy(commandString, "close digitalvideo");
  81.     return SendMCIString();
  82. }
  83.  
  84.  
  85. /*@ XVideo::OpenDevice(void)
  86. @group open/close
  87. @remarks Open the device
  88. @returns LONG resultcode
  89. */
  90. LONG XVideo::OpenDevice(void)
  91. {
  92.     strcpy(commandString, "open digitalvideo alias ");
  93.     strcat(commandString, idString);
  94.     strcat(commandString, " wait shareable");
  95.     return SendMCIString();
  96. }
  97.  
  98.  
  99. LONG XVideo::Restore(void)
  100. {
  101.     strcpy(commandString, "window ");
  102.     strcat(commandString, idString);
  103.     strcat(commandString, " state restore");
  104.     return SendMCIString();
  105. }
  106.  
  107.  
  108. /*@ XVideo::SetViewPort(const XFrameWindow * w)
  109. @group misc
  110. @remarks Set a framewindow as the viewport where videos are displayed
  111. @parameters XFrameWindow * window   the window to show the video
  112. @returns LONG resultcode
  113. */
  114. LONG XVideo::SetViewPort(const XFrameWindow * w)
  115. {
  116.     SWP swp;
  117.  
  118.     CHAR szHandle[10] = "";
  119.     CHAR szcx[5] = "";
  120.     CHAR szcy[5] = "";
  121.  
  122.     strcpy(commandString, "window ");
  123.     strcat(commandString, idString);
  124.     strcat(commandString, " handle ");
  125.  
  126.     sprintf(szHandle, "%lu", (ULONG) (WinQueryWindow(w->GetHandle(), QW_PARENT)));
  127.     strcat(commandString, szHandle);
  128.     strcat(commandString, " ");
  129.     strcat(commandString, "wait");
  130.  
  131.     LONG res = SendMCIString();
  132.  
  133.     if (res)
  134.         return res;
  135.  
  136.     strcpy(commandString, "put ");
  137.     strcat(commandString, idString);
  138.     strcat(commandString, " destination at ");
  139.     char str[20];
  140.  
  141.     WinQueryWindowPos(w->GetHandle(), &swp);
  142.     sprintf(str, "%i", (int) swp.x);
  143.     strcat(commandString, str);
  144.     strcat(commandString, " ");
  145.     sprintf(str, "%i", (int) swp.y);
  146.     strcat(commandString, str);
  147.     strcat(commandString, " ");
  148.  
  149.     sprintf(szcx, "%i", (int) (swp.cx + swp.x));
  150.     sprintf(szcy, "%i", (int) (swp.cy + swp.y));
  151.     strcat(commandString, szcx);
  152.     strcat(commandString, " ");
  153.     strcat(commandString, szcy);
  154.     strcat(commandString, " wait");
  155.  
  156.     return SendMCIString();
  157. }
  158.  
  159.  
  160. /*@ XVideo::SetVolume(const USHORT volumePercent)
  161. @group misc
  162. @remarks Set volume
  163. @parameters USHORT volume  volume in percent
  164. @returns LONG resultcode
  165. */
  166. LONG XVideo::SetVolume(const USHORT volumePercent)
  167. {
  168.     strcpy(commandString, "set ");
  169.     strcat(commandString, idString);
  170.     strcat(commandString, " audio volume ");
  171.     char bu[4];
  172.  
  173.     sprintf(bu, "%i", volumePercent);
  174.     strcat(commandString, bu);
  175.     strcat(commandString, " wait");
  176.     return SendMCIString();
  177. }
  178.  
  179.  
  180.  
  181. LONG XMediaWindow::SetDataFile(const char *p)
  182. {
  183.     strcpy(commandString, "load ");
  184.     strcat(commandString, idString);
  185.     strcat(commandString, " ");
  186.     strcat(commandString, p);
  187.     strcat(commandString, " wait");
  188.     return SendMCIString();
  189. }
  190.  
  191.  
  192.  
  193. /*@ XVideo :: ~XVideo()
  194. @group construtors/destructors
  195. @remarks The destructor MUST be called before the message-loop of an aplication is
  196. destroyed. Therefore overwrite QueryForClose() of the owning framewindow and call
  197. the destructor of XVideo in that function.
  198. */
  199. XVideo :: ~XVideo()
  200. {
  201.     strcpy(commandString, "close ");
  202.     strcat(commandString, idString);
  203.     SendMCIString();
  204. }
  205.  
  206.  
  207. /*@ XMediaWindow::Play(void)
  208. @group play functions
  209. @remarks Play the file loaded by SetDataFile
  210. @returns LONG resultcode
  211. */
  212. LONG XMediaWindow::Play(void)
  213. {
  214.     strcpy(commandString, "play ");
  215.     strcat(commandString, idString);
  216.     strcat(commandString, " notify");
  217.     return SendMCIString(MEDIA_PLAYED);
  218. }
  219.  
  220.  
  221. /*@ XMediaWindow::Pause(void)
  222. @group play functions
  223. @remarks Pause
  224. @returns LONG resultcode
  225. */
  226. LONG XMediaWindow::Pause(void)
  227. {
  228.     strcpy(commandString, "pause ");
  229.     strcat(commandString, idString);
  230.     strcat(commandString, " notify");
  231.     return SendMCIString(MEDIA_PAUSED);
  232. }
  233.  
  234.  
  235. /*@ XMediaWindow::Rewind(void)
  236. @group play functions
  237. @remarks Seek to the beginning
  238. @returns LONG resultcode
  239. */
  240. LONG XMediaWindow::Rewind(void)
  241. {
  242.     strcpy(commandString, "seek ");
  243.     strcat(commandString, idString);
  244.     strcat(commandString, " to start notify");
  245.     return SendMCIString(MEDIA_REWINDED);
  246. }
  247.  
  248.  
  249. LONG XMediaWindow::Acquire(void)
  250. {
  251.     strcpy(commandString, "acquire ");
  252.     strcat(commandString, idString);
  253.     return SendMCIString();
  254. }
  255.  
  256.  
  257. /*@ 
  258. @class XSound
  259. @parent XMediaWindow
  260. @type overview
  261. @symbol _
  262. */
  263.  
  264.  
  265. /*@ XSound::SetVolume(const USHORT volPercent)
  266. @group misc
  267. @remarks Set volume
  268. @parameters USHORT volume  volume in percent
  269. @returns LONG resultcode
  270. */
  271. LONG XSound::SetVolume(const USHORT volPercent)
  272. {
  273.     if (type == 0)
  274.         return 0;
  275.  
  276.     strcpy(commandString, "set ");
  277.     strcat(commandString, idString);
  278.     if (type == WAVE)
  279.         strcat(commandString, " audio");
  280.     strcat(commandString, " volume ");
  281.     char bu[4];
  282.  
  283.     sprintf(bu, "%i", volPercent);
  284.     strcat(commandString, bu);
  285.     strcat(commandString, " wait");
  286.     return SendMCIString();
  287. }
  288.  
  289.  
  290. /*@ XSound::SetDataFile(const char *p)
  291. @group misc
  292. @remarks Play a new file
  293. @parameters char * p    the file to play
  294. @returns LONG resultcode
  295. */
  296. LONG XSound::SetDataFile(const char *p)
  297. {
  298.     if (((strstr(p, ".MID") || strstr(p, ".mid")) && type != MIDI) || ((strstr(p, ".WAV") || strstr(p, ".wav")) && type != WAVE))
  299.         OpenDevice(p);
  300.  
  301.     return XMediaWindow::SetDataFile(p);
  302. }
  303.  
  304.  
  305.  
  306. /*@ XSound :: ~XSound()
  307. @group constructors/destructors
  308. @remarks The destructor MUST be called before the message-loop of an aplication is
  309. destroyed. Therefore overwrite QueryForClose() of the owning framewindow and call
  310. the destructor of XSound in that function.
  311. */
  312. XSound :: ~XSound()
  313. {
  314.     if (type != 0)
  315.     {
  316.         strcpy(commandString, "close ");
  317.         strcat(commandString, idString);
  318.         type = 0;
  319.         SendMCIString();
  320.     }
  321. }
  322.  
  323.  
  324. /*@ XSound :: XSound(const XFrameWindow * w)
  325. @group constructors/destructors
  326. @remarks Construct a sound-device. XSound can play MIDI and WAV-files. To use this control you must invoke the multimedia-library!
  327. @parameters XFrameWindow * owner    the owner of the device
  328. */
  329. XSound :: XSound(const XFrameWindow * w):XMediaWindow(w)
  330. {
  331.     sprintf(idString, "OOL_Audio%u", (unsigned int) mediaId);
  332. }
  333.  
  334.  
  335.  
  336. /*@ XSound::OpenDevice(const char *p)
  337. @group open/close
  338. @remarks Open the device
  339. @parameters char * p    file to play
  340. @returns LONG resultcode
  341. */
  342. LONG XSound::OpenDevice(const char *p)
  343. {
  344.     LONG res = 0;
  345.  
  346.     if (type != 0)
  347.     {
  348.         strcpy(commandString, "close ");
  349.         strcat(commandString, idString);
  350.         type = 0;
  351.         SendMCIString();
  352.     }
  353.  
  354.     if (p)
  355.     {
  356.         if (strstr(p, ".WAV"))
  357.         {
  358.             type = WAVE;
  359.             strcpy(commandString, "open waveaudio alias ");
  360.         }
  361.         else if (strstr(p, ".MID"))
  362.         {
  363.             strcpy(commandString, "open sequencer alias ");
  364.             type = MIDI;
  365.         }
  366.     }
  367.  
  368.     if (type)
  369.     {
  370.         strcat(commandString, idString);
  371.         strcat(commandString, " wait shareable");
  372.         if ((res = SendMCIString()) != 0)
  373.             return res;
  374.         strcpy(commandString, "capability ");
  375.         strcat(commandString, idString);
  376.         strcat(commandString, " can play wait");
  377.         res = SendMCIString();
  378.     }
  379.     return res;
  380. }
  381.