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.

80 lines
3.6KB

  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. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /** Wraps another input stream, and reads from a specific part of it.
  20. This lets you take a subsection of a stream and present it as an entire
  21. stream in its own right.
  22. */
  23. class JUCE_API SubregionStream : public InputStream
  24. {
  25. public:
  26. //==============================================================================
  27. /** Creates a SubregionStream from an input source.
  28. @param sourceStream the source stream to read from
  29. @param startPositionInSourceStream this is the position in the source stream that
  30. corresponds to position 0 in this stream
  31. @param lengthOfSourceStream this specifies the maximum number of bytes
  32. from the source stream that will be passed through
  33. by this stream. When the position of this stream
  34. exceeds lengthOfSourceStream, it will cause an end-of-stream.
  35. If the length passed in here is greater than the length
  36. of the source stream (as returned by getTotalLength()),
  37. then the smaller value will be used.
  38. Passing a negative value for this parameter means it
  39. will keep reading until the source's end-of-stream.
  40. @param deleteSourceWhenDestroyed whether the sourceStream that is passed in should be
  41. deleted by this object when it is itself deleted.
  42. */
  43. SubregionStream (InputStream* sourceStream,
  44. int64 startPositionInSourceStream,
  45. int64 lengthOfSourceStream,
  46. bool deleteSourceWhenDestroyed);
  47. /** Destructor.
  48. This may also delete the source stream, if that option was chosen when the
  49. buffered stream was created.
  50. */
  51. ~SubregionStream();
  52. //==============================================================================
  53. int64 getTotalLength() override;
  54. int64 getPosition() override;
  55. bool setPosition (int64 newPosition) override;
  56. int read (void* destBuffer, int maxBytesToRead) override;
  57. bool isExhausted() override;
  58. private:
  59. //==============================================================================
  60. OptionalScopedPointer<InputStream> source;
  61. const int64 startPositionInSourceStream, lengthOfSourceStream;
  62. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SubregionStream)
  63. };