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.

84 lines
3.7KB

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