Audio plugin host https://kx.studio/carla
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.

99 lines
3.7KB

  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_FILEINPUTSTREAM_H_INCLUDED
  24. #define JUCE_FILEINPUTSTREAM_H_INCLUDED
  25. //==============================================================================
  26. /**
  27. An input stream that reads from a local file.
  28. @see InputStream, FileOutputStream, File::createInputStream
  29. */
  30. class JUCE_API FileInputStream : public InputStream
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates a FileInputStream to read from the given file.
  35. After creating a FileInputStream, you should use openedOk() or failedToOpen()
  36. to make sure that it's OK before trying to read from it! If it failed, you
  37. can call getStatus() to get more error information.
  38. */
  39. explicit FileInputStream (const File& fileToRead);
  40. /** Destructor. */
  41. ~FileInputStream();
  42. //==============================================================================
  43. /** Returns the file that this stream is reading from. */
  44. const File& getFile() const noexcept { return file; }
  45. /** Returns the status of the file stream.
  46. The result will be ok if the file opened successfully. If an error occurs while
  47. opening or reading from the file, this will contain an error message.
  48. */
  49. const Result& getStatus() const noexcept { return status; }
  50. /** Returns true if the stream couldn't be opened for some reason.
  51. @see getResult()
  52. */
  53. bool failedToOpen() const noexcept { return status.failed(); }
  54. /** Returns true if the stream opened without problems.
  55. @see getResult()
  56. */
  57. bool openedOk() const noexcept { return status.wasOk(); }
  58. //==============================================================================
  59. int64 getTotalLength() override;
  60. int read (void*, int) override;
  61. bool isExhausted() override;
  62. int64 getPosition() override;
  63. bool setPosition (int64) override;
  64. private:
  65. //==============================================================================
  66. const File file;
  67. void* fileHandle;
  68. int64 currentPosition;
  69. Result status;
  70. void openHandle();
  71. size_t readInternal (void*, size_t);
  72. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileInputStream)
  73. };
  74. #endif // JUCE_FILEINPUTSTREAM_H_INCLUDED