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.

160 lines
6.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. class AudioThumbnailCache;
  22. //==============================================================================
  23. /**
  24. Provides a base for classes that can store and draw scaled views of an
  25. audio waveform.
  26. Typically, you'll want to use the derived class AudioThumbnail, which provides
  27. a concrete implementation.
  28. @see AudioThumbnail, AudioThumbnailCache
  29. @tags{Audio}
  30. */
  31. class JUCE_API AudioThumbnailBase : public ChangeBroadcaster,
  32. public AudioFormatWriter::ThreadedWriter::IncomingDataReceiver
  33. {
  34. public:
  35. //==============================================================================
  36. AudioThumbnailBase() {}
  37. virtual ~AudioThumbnailBase() {}
  38. //==============================================================================
  39. /** Clears and resets the thumbnail. */
  40. virtual void clear() = 0;
  41. /** Specifies the file or stream that contains the audio file.
  42. For a file, just call
  43. @code
  44. setSource (new FileInputSource (file))
  45. @endcode
  46. You can pass a nullptr in here to clear the thumbnail.
  47. The source that is passed in will be deleted by this object when it is no longer needed.
  48. @returns true if the source could be opened as a valid audio file, false if this failed for
  49. some reason.
  50. */
  51. virtual bool setSource (InputSource* newSource) = 0;
  52. /** Gives the thumbnail an AudioFormatReader to use directly.
  53. This will start parsing the audio in a background thread (unless the hash code
  54. can be looked-up successfully in the thumbnail cache). Note that the reader
  55. object will be held by the thumbnail and deleted later when no longer needed.
  56. The thumbnail will actually keep hold of this reader until you clear the thumbnail
  57. or change the input source, so the file will be held open for all this time. If
  58. you don't want the thumbnail to keep a file handle open continuously, you
  59. should use the setSource() method instead, which will only open the file when
  60. it needs to.
  61. */
  62. virtual void setReader (AudioFormatReader* newReader, int64 hashCode) = 0;
  63. //==============================================================================
  64. /** Reloads the low res thumbnail data from an input stream.
  65. This is not an audio file stream! It takes a stream of thumbnail data that would
  66. previously have been created by the saveTo() method.
  67. @see saveTo
  68. */
  69. virtual bool loadFrom (InputStream& input) = 0;
  70. /** Saves the low res thumbnail data to an output stream.
  71. The data that is written can later be reloaded using loadFrom().
  72. @see loadFrom
  73. */
  74. virtual void saveTo (OutputStream& output) const = 0;
  75. //==============================================================================
  76. /** Returns the number of channels in the file. */
  77. virtual int getNumChannels() const noexcept = 0;
  78. /** Returns the length of the audio file, in seconds. */
  79. virtual double getTotalLength() const noexcept = 0;
  80. /** Draws the waveform for a channel.
  81. The waveform will be drawn within the specified rectangle, where startTime
  82. and endTime specify the times within the audio file that should be positioned
  83. at the left and right edges of the rectangle.
  84. The waveform will be scaled vertically so that a full-volume sample will fill
  85. the rectangle vertically, but you can also specify an extra vertical scale factor
  86. with the verticalZoomFactor parameter.
  87. */
  88. virtual void drawChannel (Graphics& g,
  89. const Rectangle<int>& area,
  90. double startTimeSeconds,
  91. double endTimeSeconds,
  92. int channelNum,
  93. float verticalZoomFactor) = 0;
  94. /** Draws the waveforms for all channels in the thumbnail.
  95. This will call drawChannel() to render each of the thumbnail's channels, stacked
  96. above each other within the specified area.
  97. @see drawChannel
  98. */
  99. virtual void drawChannels (Graphics& g,
  100. const Rectangle<int>& area,
  101. double startTimeSeconds,
  102. double endTimeSeconds,
  103. float verticalZoomFactor) = 0;
  104. /** Returns true if the low res preview is fully generated. */
  105. virtual bool isFullyLoaded() const noexcept = 0;
  106. /** Returns the number of samples that have been set in the thumbnail. */
  107. virtual int64 getNumSamplesFinished() const noexcept = 0;
  108. /** Returns the highest level in the thumbnail.
  109. Note that because the thumb only stores low-resolution data, this isn't
  110. an accurate representation of the highest value, it's only a rough approximation.
  111. */
  112. virtual float getApproximatePeak() const = 0;
  113. /** Reads the approximate min and max levels from a section of the thumbnail.
  114. The lowest and highest samples are returned in minValue and maxValue, but obviously
  115. because the thumb only stores low-resolution data, these numbers will only be a rough
  116. approximation of the true values.
  117. */
  118. virtual void getApproximateMinMax (double startTime, double endTime, int channelIndex,
  119. float& minValue, float& maxValue) const noexcept = 0;
  120. /** Returns the hash code that was set by setSource() or setReader(). */
  121. virtual int64 getHashCode() const = 0;
  122. };
  123. } // namespace juce