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.

146 lines
5.5KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE 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. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_AUDIOFORMATMANAGER_JUCEHEADER__
  19. #define __JUCE_AUDIOFORMATMANAGER_JUCEHEADER__
  20. #include "juce_AudioFormat.h"
  21. #include "../../core/juce_Singleton.h"
  22. #include "../../containers/juce_VoidArray.h"
  23. //==============================================================================
  24. /**
  25. A class for keeping a list of available audio formats, and for deciding which
  26. one to use to open a given file.
  27. You can either use this class as a singleton object, or create instances of it
  28. yourself. Once created, use its registerFormat() method to tell it which
  29. formats it should use.
  30. @see AudioFormat
  31. */
  32. class JUCE_API AudioFormatManager
  33. {
  34. public:
  35. //==============================================================================
  36. /** Creates an empty format manager.
  37. Before it'll be any use, you'll need to call registerFormat() with all the
  38. formats you want it to be able to recognise.
  39. */
  40. AudioFormatManager();
  41. /** Destructor. */
  42. ~AudioFormatManager();
  43. juce_DeclareSingleton (AudioFormatManager, false);
  44. //==============================================================================
  45. /** Adds a format to the manager's list of available file types.
  46. The object passed-in will be deleted by this object, so don't keep a pointer
  47. to it!
  48. If makeThisTheDefaultFormat is true, then the getDefaultFormat() method will
  49. return this one when called.
  50. */
  51. void registerFormat (AudioFormat* newFormat,
  52. const bool makeThisTheDefaultFormat);
  53. /** Handy method to make it easy to register the formats that come with Juce.
  54. Currently, this will add WAV and AIFF to the list.
  55. */
  56. void registerBasicFormats();
  57. /** Clears the list of known formats. */
  58. void clearFormats();
  59. /** Returns the number of currently registered file formats. */
  60. int getNumKnownFormats() const;
  61. /** Returns one of the registered file formats. */
  62. AudioFormat* getKnownFormat (const int index) const;
  63. /** Looks for which of the known formats is listed as being for a given file
  64. extension.
  65. The extension may have a dot before it, so e.g. ".wav" or "wav" are both ok.
  66. */
  67. AudioFormat* findFormatForFileExtension (const String& fileExtension) const;
  68. /** Returns the format which has been set as the default one.
  69. You can set a format as being the default when it is registered. It's useful
  70. when you want to write to a file, because the best format may change between
  71. platforms, e.g. AIFF is preferred on the Mac, WAV on Windows.
  72. If none has been set as the default, this method will just return the first
  73. one in the list.
  74. */
  75. AudioFormat* getDefaultFormat() const;
  76. /** Returns a set of wildcards for file-matching that contains the extensions for
  77. all known formats.
  78. E.g. if might return "*.wav;*.aiff" if it just knows about wavs and aiffs.
  79. */
  80. const String getWildcardForAllFormats() const;
  81. //==============================================================================
  82. /** Searches through the known formats to try to create a suitable reader for
  83. this file.
  84. If none of the registered formats can open the file, it'll return 0. If it
  85. returns a reader, it's the caller's responsibility to delete the reader.
  86. */
  87. AudioFormatReader* createReaderFor (const File& audioFile);
  88. /** Searches through the known formats to try to create a suitable reader for
  89. this stream.
  90. The stream object that is passed-in will be deleted by this method or by the
  91. reader that is returned, so the caller should not keep any references to it.
  92. The stream that is passed-in must be capable of being repositioned so
  93. that all the formats can have a go at opening it.
  94. If none of the registered formats can open the stream, it'll return 0. If it
  95. returns a reader, it's the caller's responsibility to delete the reader.
  96. */
  97. AudioFormatReader* createReaderFor (InputStream* audioFileStream);
  98. //==============================================================================
  99. juce_UseDebuggingNewOperator
  100. private:
  101. VoidArray knownFormats;
  102. int defaultFormatIndex;
  103. };
  104. #endif // __JUCE_AUDIOFORMATMANAGER_JUCEHEADER__