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.

221 lines
7.7KB

  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_QUICKTIMEMOVIECOMPONENT_H_INCLUDED
  18. #define JUCE_QUICKTIMEMOVIECOMPONENT_H_INCLUDED
  19. // (NB: This stuff mustn't go inside the "#if QUICKTIME" block, or it'll break the
  20. // amalgamated build)
  21. #ifndef DOXYGEN
  22. #if JUCE_WINDOWS
  23. typedef ActiveXControlComponent QTCompBaseClass;
  24. #elif JUCE_MAC
  25. typedef NSViewComponent QTCompBaseClass;
  26. #endif
  27. #endif
  28. #if JUCE_QUICKTIME || DOXYGEN
  29. //==============================================================================
  30. /**
  31. A window that can play back a QuickTime movie.
  32. */
  33. class JUCE_API QuickTimeMovieComponent : public QTCompBaseClass
  34. {
  35. public:
  36. //==============================================================================
  37. /** Creates a QuickTimeMovieComponent, initially blank.
  38. Use the loadMovie() method to load a movie once you've added the
  39. component to a window, (or put it on the desktop as a heavyweight window).
  40. Loading a movie when the component isn't visible can cause problems, as
  41. QuickTime needs a window handle to initialise properly.
  42. */
  43. QuickTimeMovieComponent();
  44. /** Destructor. */
  45. ~QuickTimeMovieComponent();
  46. /** Returns true if QT is installed and working on this machine.
  47. */
  48. static bool isQuickTimeAvailable() noexcept;
  49. //==============================================================================
  50. /** Tries to load a QuickTime movie from a file into the player.
  51. It's best to call this function once you've added the component to a window,
  52. (or put it on the desktop as a heavyweight window). Loading a movie when the
  53. component isn't visible can cause problems, because QuickTime needs a window
  54. handle to do its stuff.
  55. @param movieFile the .mov file to open
  56. @param isControllerVisible whether to show a controller bar at the bottom
  57. @returns true if the movie opens successfully
  58. */
  59. bool loadMovie (const File& movieFile,
  60. bool isControllerVisible);
  61. /** Tries to load a QuickTime movie from a URL into the player.
  62. It's best to call this function once you've added the component to a window,
  63. (or put it on the desktop as a heavyweight window). Loading a movie when the
  64. component isn't visible can cause problems, because QuickTime needs a window
  65. handle to do its stuff.
  66. @param movieURL the .mov file to open
  67. @param isControllerVisible whether to show a controller bar at the bottom
  68. @returns true if the movie opens successfully
  69. */
  70. bool loadMovie (const URL& movieURL,
  71. bool isControllerVisible);
  72. /** Tries to load a QuickTime movie from a stream into the player.
  73. It's best to call this function once you've added the component to a window,
  74. (or put it on the desktop as a heavyweight window). Loading a movie when the
  75. component isn't visible can cause problems, because QuickTime needs a window
  76. handle to do its stuff.
  77. @param movieStream a stream containing a .mov file. The component may try
  78. to read the whole stream before playing, rather than
  79. streaming from it.
  80. @param isControllerVisible whether to show a controller bar at the bottom
  81. @returns true if the movie opens successfully
  82. */
  83. bool loadMovie (InputStream* movieStream,
  84. bool isControllerVisible);
  85. /** Closes the movie, if one is open. */
  86. void closeMovie();
  87. /** Returns the movie file that is currently open.
  88. If there isn't one, this returns File::nonexistent
  89. */
  90. File getCurrentMovieFile() const;
  91. /** Returns true if there's currently a movie open. */
  92. bool isMovieOpen() const;
  93. /** Returns the length of the movie, in seconds. */
  94. double getMovieDuration() const;
  95. /** Returns the movie's natural size, in pixels.
  96. You can use this to resize the component to show the movie at its preferred
  97. scale.
  98. If no movie is loaded, the size returned will be 0 x 0.
  99. */
  100. void getMovieNormalSize (int& width, int& height) const;
  101. /** This will position the component within a given area, keeping its aspect
  102. ratio correct according to the movie's normal size.
  103. The component will be made as large as it can go within the space, and will
  104. be aligned according to the justification value if this means there are gaps at
  105. the top or sides.
  106. */
  107. void setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  108. RectanglePlacement placement);
  109. /** Starts the movie playing. */
  110. void play();
  111. /** Stops the movie playing. */
  112. void stop();
  113. /** Returns true if the movie is currently playing. */
  114. bool isPlaying() const;
  115. /** Moves the movie's position back to the start. */
  116. void goToStart();
  117. /** Sets the movie's position to a given time. */
  118. void setPosition (double seconds);
  119. /** Returns the current play position of the movie. */
  120. double getPosition() const;
  121. /** Changes the movie playback rate.
  122. A value of 1 is normal speed, greater values play it proportionately faster,
  123. smaller values play it slower.
  124. */
  125. void setSpeed (float newSpeed);
  126. /** Changes the movie's playback volume.
  127. @param newVolume the volume in the range 0 (silent) to 1.0 (full)
  128. */
  129. void setMovieVolume (float newVolume);
  130. /** Returns the movie's playback volume.
  131. @returns the volume in the range 0 (silent) to 1.0 (full)
  132. */
  133. float getMovieVolume() const;
  134. /** Tells the movie whether it should loop. */
  135. void setLooping (bool shouldLoop);
  136. /** Returns true if the movie is currently looping.
  137. @see setLooping
  138. */
  139. bool isLooping() const;
  140. /** True if the native QuickTime controller bar is shown in the window.
  141. @see loadMovie
  142. */
  143. bool isControllerVisible() const;
  144. //==============================================================================
  145. /** @internal */
  146. void paint (Graphics&) override;
  147. private:
  148. //==============================================================================
  149. File movieFile;
  150. bool movieLoaded, controllerVisible, looping;
  151. #if JUCE_WINDOWS
  152. void parentHierarchyChanged() override;
  153. void visibilityChanged() override;
  154. void createControlIfNeeded();
  155. bool isControlCreated() const;
  156. class Pimpl;
  157. friend struct ContainerDeletePolicy<Pimpl>;
  158. ScopedPointer<Pimpl> pimpl;
  159. #else
  160. void* movie;
  161. #endif
  162. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (QuickTimeMovieComponent)
  163. };
  164. #endif
  165. #endif // JUCE_QUICKTIMEMOVIECOMPONENT_H_INCLUDED