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.

90 lines
4.0KB

  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_SUBREGIONSTREAM_JUCEHEADER__
  19. #define __JUCE_SUBREGIONSTREAM_JUCEHEADER__
  20. #include "juce_InputStream.h"
  21. #include "../memory/juce_OptionalScopedPointer.h"
  22. //==============================================================================
  23. /** Wraps another input stream, and reads from a specific part of it.
  24. This lets you take a subsection of a stream and present it as an entire
  25. stream in its own right.
  26. */
  27. class JUCE_API SubregionStream : public InputStream
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a SubregionStream from an input source.
  32. @param sourceStream the source stream to read from
  33. @param startPositionInSourceStream this is the position in the source stream that
  34. corresponds to position 0 in this stream
  35. @param lengthOfSourceStream this specifies the maximum number of bytes
  36. from the source stream that will be passed through
  37. by this stream. When the position of this stream
  38. exceeds lengthOfSourceStream, it will cause an end-of-stream.
  39. If the length passed in here is greater than the length
  40. of the source stream (as returned by getTotalLength()),
  41. then the smaller value will be used.
  42. Passing a negative value for this parameter means it
  43. will keep reading until the source's end-of-stream.
  44. @param deleteSourceWhenDestroyed whether the sourceStream that is passed in should be
  45. deleted by this object when it is itself deleted.
  46. */
  47. SubregionStream (InputStream* sourceStream,
  48. int64 startPositionInSourceStream,
  49. int64 lengthOfSourceStream,
  50. bool deleteSourceWhenDestroyed);
  51. /** Destructor.
  52. This may also delete the source stream, if that option was chosen when the
  53. buffered stream was created.
  54. */
  55. ~SubregionStream();
  56. //==============================================================================
  57. int64 getTotalLength();
  58. int64 getPosition();
  59. bool setPosition (int64 newPosition);
  60. int read (void* destBuffer, int maxBytesToRead);
  61. bool isExhausted();
  62. //==============================================================================
  63. private:
  64. OptionalScopedPointer<InputStream> source;
  65. const int64 startPositionInSourceStream, lengthOfSourceStream;
  66. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SubregionStream)
  67. };
  68. #endif // __JUCE_SUBREGIONSTREAM_JUCEHEADER__