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.

157 lines
6.8KB

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