The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
7.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_DIRECTSHOWCOMPONENT_H_INCLUDED
  18. #define JUCE_DIRECTSHOWCOMPONENT_H_INCLUDED
  19. #if JUCE_DIRECTSHOW || DOXYGEN
  20. //==============================================================================
  21. /**
  22. A window that can play back a DirectShow video.
  23. @note Controller is not implemented
  24. */
  25. class JUCE_API DirectShowComponent : public Component
  26. {
  27. public:
  28. //==============================================================================
  29. /** DirectShow video renderer type.
  30. See MSDN for advice about choosing the right renderer.
  31. */
  32. enum VideoRendererType
  33. {
  34. dshowDefault, /**< VMR7 for Windows XP, EVR for Windows Vista and later */
  35. dshowVMR7, /**< Video Mixing Renderer 7 */
  36. dshowEVR /**< Enhanced Video Renderer */
  37. };
  38. /** Creates a DirectShowComponent, initially blank.
  39. Use the loadMovie() method to load a video once you've added the
  40. component to a window, (or put it on the desktop as a heavyweight window).
  41. Loading a video when the component isn't visible can cause problems, as
  42. DirectShow needs a window handle to initialise properly.
  43. @see VideoRendererType
  44. */
  45. DirectShowComponent (VideoRendererType type = dshowDefault);
  46. /** Destructor. */
  47. ~DirectShowComponent();
  48. /** Returns true if DirectShow is installed and working on this machine. */
  49. static bool isDirectShowAvailable();
  50. //==============================================================================
  51. /** Tries to load a DirectShow video from a file or URL into the player.
  52. It's best to call this function once you've added the component to a window,
  53. (or put it on the desktop as a heavyweight window). Loading a video when the
  54. component isn't visible can cause problems, because DirectShow needs a window
  55. handle to do its stuff.
  56. @param fileOrURLPath the file or URL path to open
  57. @returns true if the video opens successfully
  58. */
  59. bool loadMovie (const String& fileOrURLPath);
  60. /** Tries to load a DirectShow video from a file into the player.
  61. It's best to call this function once you've added the component to a window,
  62. (or put it on the desktop as a heavyweight window). Loading a video when the
  63. component isn't visible can cause problems, because DirectShow needs a window
  64. handle to do its stuff.
  65. @param videoFile the video file to open
  66. @returns true if the video opens successfully
  67. */
  68. bool loadMovie (const File& videoFile);
  69. /** Tries to load a DirectShow video from a URL into the player.
  70. It's best to call this function once you've added the component to a window,
  71. (or put it on the desktop as a heavyweight window). Loading a video when the
  72. component isn't visible can cause problems, because DirectShow needs a window
  73. handle to do its stuff.
  74. @param videoURL the video URL to open
  75. @returns true if the video opens successfully
  76. */
  77. bool loadMovie (const URL& videoURL);
  78. /** Closes the video, if one is open. */
  79. void closeMovie();
  80. /** Returns the file path or URL from which the video file was loaded.
  81. If there isn't one, this returns an empty string.
  82. */
  83. File getCurrentMoviePath() const;
  84. /** Returns true if there's currently a video open. */
  85. bool isMovieOpen() const;
  86. /** Returns the length of the video, in seconds. */
  87. double getMovieDuration() const;
  88. /** Returns the video's natural size, in pixels.
  89. You can use this to resize the component to show the video at its preferred
  90. scale.
  91. If no video is loaded, the size returned will be 0 x 0.
  92. */
  93. void getMovieNormalSize (int& width, int& height) const;
  94. /** This will position the component within a given area, keeping its aspect
  95. ratio correct according to the video's normal size.
  96. The component will be made as large as it can go within the space, and will
  97. be aligned according to the justification value if this means there are gaps at
  98. the top or sides.
  99. @note Not implemented
  100. */
  101. void setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  102. RectanglePlacement placement);
  103. /** Starts the video playing. */
  104. void play();
  105. /** Stops the video playing. */
  106. void stop();
  107. /** Returns true if the video is currently playing. */
  108. bool isPlaying() const;
  109. /** Moves the video's position back to the start. */
  110. void goToStart();
  111. /** Sets the video's position to a given time. */
  112. void setPosition (double seconds);
  113. /** Returns the current play position of the video. */
  114. double getPosition() const;
  115. /** Changes the video playback rate.
  116. A value of 1 is normal speed, greater values play it proportionately faster,
  117. smaller values play it slower.
  118. */
  119. void setSpeed (float newSpeed);
  120. /** Changes the video's playback volume.
  121. @param newVolume the volume in the range 0 (silent) to 1.0 (full)
  122. */
  123. void setMovieVolume (float newVolume);
  124. /** Returns the video's playback volume.
  125. @returns the volume in the range 0 (silent) to 1.0 (full)
  126. */
  127. float getMovieVolume() const;
  128. /** Tells the video whether it should loop. */
  129. void setLooping (bool shouldLoop);
  130. /** Returns true if the video is currently looping.
  131. @see setLooping
  132. */
  133. bool isLooping() const;
  134. //==============================================================================
  135. /** @internal */
  136. void paint (Graphics&) override;
  137. private:
  138. //==============================================================================
  139. String videoPath;
  140. bool videoLoaded, looping;
  141. class DirectShowContext;
  142. friend class DirectShowContext;
  143. friend struct ContainerDeletePolicy<DirectShowContext>;
  144. ScopedPointer<DirectShowContext> context;
  145. class DirectShowComponentWatcher;
  146. friend class DirectShowComponentWatcher;
  147. friend struct ContainerDeletePolicy<DirectShowComponentWatcher>;
  148. ScopedPointer<DirectShowComponentWatcher> componentWatcher;
  149. //==============================================================================
  150. void updateContextPosition();
  151. void showContext (bool shouldBeVisible);
  152. void recreateNativeWindowAsync();
  153. //==============================================================================
  154. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DirectShowComponent)
  155. };
  156. #endif
  157. #endif // JUCE_DIRECTSHOWCOMPONENT_H_INCLUDED