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.

91 lines
4.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_SUBREGIONSTREAM_H_INCLUDED
  24. #define JUCE_SUBREGIONSTREAM_H_INCLUDED
  25. //==============================================================================
  26. /** Wraps another input stream, and reads from a specific part of it.
  27. This lets you take a subsection of a stream and present it as an entire
  28. stream in its own right.
  29. */
  30. class JUCE_API SubregionStream : public InputStream
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates a SubregionStream from an input source.
  35. @param sourceStream the source stream to read from
  36. @param startPositionInSourceStream this is the position in the source stream that
  37. corresponds to position 0 in this stream
  38. @param lengthOfSourceStream this specifies the maximum number of bytes
  39. from the source stream that will be passed through
  40. by this stream. When the position of this stream
  41. exceeds lengthOfSourceStream, it will cause an end-of-stream.
  42. If the length passed in here is greater than the length
  43. of the source stream (as returned by getTotalLength()),
  44. then the smaller value will be used.
  45. Passing a negative value for this parameter means it
  46. will keep reading until the source's end-of-stream.
  47. @param deleteSourceWhenDestroyed whether the sourceStream that is passed in should be
  48. deleted by this object when it is itself deleted.
  49. */
  50. SubregionStream (InputStream* sourceStream,
  51. int64 startPositionInSourceStream,
  52. int64 lengthOfSourceStream,
  53. bool deleteSourceWhenDestroyed);
  54. /** Destructor.
  55. This may also delete the source stream, if that option was chosen when the
  56. buffered stream was created.
  57. */
  58. ~SubregionStream();
  59. //==============================================================================
  60. int64 getTotalLength() override;
  61. int64 getPosition() override;
  62. bool setPosition (int64 newPosition) override;
  63. int read (void* destBuffer, int maxBytesToRead) override;
  64. bool isExhausted() override;
  65. private:
  66. //==============================================================================
  67. OptionalScopedPointer<InputStream> source;
  68. const int64 startPositionInSourceStream, lengthOfSourceStream;
  69. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SubregionStream)
  70. };
  71. #endif // JUCE_SUBREGIONSTREAM_H_INCLUDED