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.

148 lines
5.4KB

  1. /*
  2. ==============================================================================
  3. This file is part of the Water library.
  4. Copyright (c) 2015 ROLI Ltd.
  5. Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
  6. Permission is granted to use this software under the terms of either:
  7. a) the GPL v2 (or any later version)
  8. b) the Affero GPL v3
  9. Details of these licenses can be found at: www.gnu.org/licenses
  10. Water 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. */
  15. #ifndef WATER_AUDIOFORMATMANAGER_H_INCLUDED
  16. #define WATER_AUDIOFORMATMANAGER_H_INCLUDED
  17. #include "AudioFormat.h"
  18. #include "../containers/OwnedArray.h"
  19. #include "../text/String.h"
  20. #include "CarlaJuceUtils.hpp"
  21. namespace water {
  22. //==============================================================================
  23. /**
  24. A class for keeping a list of available audio formats, and for deciding which
  25. one to use to open a given file.
  26. After creating an AudioFormatManager object, you should call registerFormat()
  27. or registerBasicFormats() to give it a list of format types that it can use.
  28. @see AudioFormat
  29. */
  30. class AudioFormatManager
  31. {
  32. public:
  33. //==============================================================================
  34. /** Creates an empty format manager.
  35. Before it'll be any use, you'll need to call registerFormat() with all the
  36. formats you want it to be able to recognise.
  37. */
  38. AudioFormatManager();
  39. /** Destructor. */
  40. ~AudioFormatManager();
  41. //==============================================================================
  42. /** Adds a format to the manager's list of available file types.
  43. The object passed-in will be deleted by this object, so don't keep a pointer
  44. to it!
  45. If makeThisTheDefaultFormat is true, then the getDefaultFormat() method will
  46. return this one when called.
  47. */
  48. void registerFormat (AudioFormat* newFormat,
  49. bool makeThisTheDefaultFormat);
  50. /** Handy method to make it easy to register the formats that come with Water.
  51. Currently, this will add WAV and AIFF to the list.
  52. */
  53. void registerBasicFormats();
  54. /** Clears the list of known formats. */
  55. void clearFormats();
  56. /** Returns the number of currently registered file formats. */
  57. int getNumKnownFormats() const;
  58. /** Returns one of the registered file formats. */
  59. AudioFormat* getKnownFormat (int index) const;
  60. /** Iterator access to the list of known formats. */
  61. AudioFormat** begin() const noexcept { return knownFormats.begin(); }
  62. /** Iterator access to the list of known formats. */
  63. AudioFormat** end() const noexcept { return knownFormats.end(); }
  64. /** Looks for which of the known formats is listed as being for a given file
  65. extension.
  66. The extension may have a dot before it, so e.g. ".wav" or "wav" are both ok.
  67. */
  68. AudioFormat* findFormatForFileExtension (const String& fileExtension) const;
  69. /** Returns the format which has been set as the default one.
  70. You can set a format as being the default when it is registered. It's useful
  71. when you want to write to a file, because the best format may change between
  72. platforms, e.g. AIFF is preferred on the Mac, WAV on Windows.
  73. If none has been set as the default, this method will just return the first
  74. one in the list.
  75. */
  76. AudioFormat* getDefaultFormat() const;
  77. /** Returns a set of wildcards for file-matching that contains the extensions for
  78. all known formats.
  79. E.g. if might return "*.wav;*.aiff" if it just knows about wavs and aiffs.
  80. */
  81. String getWildcardForAllFormats() const;
  82. //==============================================================================
  83. /** Searches through the known formats to try to create a suitable reader for
  84. this file.
  85. If none of the registered formats can open the file, it'll return 0. If it
  86. returns a reader, it's the caller's responsibility to delete the reader.
  87. */
  88. AudioFormatReader* createReaderFor (const File& audioFile);
  89. /** Searches through the known formats to try to create a suitable reader for
  90. this stream.
  91. The stream object that is passed-in will be deleted by this method or by the
  92. reader that is returned, so the caller should not keep any references to it.
  93. The stream that is passed-in must be capable of being repositioned so
  94. that all the formats can have a go at opening it.
  95. If none of the registered formats can open the stream, it'll return nullptr.
  96. If it returns a reader, it's the caller's responsibility to delete the reader.
  97. */
  98. AudioFormatReader* createReaderFor (InputStream* audioFileStream);
  99. private:
  100. //==============================================================================
  101. OwnedArray<AudioFormat> knownFormats;
  102. int defaultFormatIndex;
  103. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioFormatManager)
  104. };
  105. }
  106. #endif // WATER_AUDIOFORMATMANAGER_H_INCLUDED