JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_AudioFormatManager.cpp
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
31
32//==============================================================================
34{
35 jassert (newFormat != nullptr);
36
37 if (newFormat != nullptr)
38 {
39 #if JUCE_DEBUG
40 for (auto* af : knownFormats)
41 {
42 if (af->getFormatName() == newFormat->getFormatName())
43 jassertfalse; // trying to add the same format twice!
44 }
45 #endif
46
48 defaultFormatIndex = getNumKnownFormats();
49
50 knownFormats.add (newFormat);
51 }
52}
53
55{
56 registerFormat (new WavAudioFormat(), true);
57 registerFormat (new AiffAudioFormat(), false);
58
59 #if JUCE_USE_FLAC
60 registerFormat (new FlacAudioFormat(), false);
61 #endif
62
63 #if JUCE_USE_OGGVORBIS
65 #endif
66
67 #if JUCE_MAC || JUCE_IOS
68 registerFormat (new CoreAudioFormat(), false);
69 #endif
70
71 #if JUCE_USE_MP3AUDIOFORMAT
72 registerFormat (new MP3AudioFormat(), false);
73 #endif
74
75 #if JUCE_USE_WINDOWS_MEDIA_FORMAT
77 #endif
78}
79
81{
82 knownFormats.clear();
83 defaultFormatIndex = 0;
84}
85
86int AudioFormatManager::getNumKnownFormats() const { return knownFormats.size(); }
87AudioFormat* AudioFormatManager::getKnownFormat (int index) const { return knownFormats[index]; }
88AudioFormat* AudioFormatManager::getDefaultFormat() const { return getKnownFormat (defaultFormatIndex); }
89
91{
92 if (! fileExtension.startsWithChar ('.'))
93 return findFormatForFileExtension ("." + fileExtension);
94
95 for (auto* af : knownFormats)
96 if (af->getFileExtensions().contains (fileExtension, true))
97 return af;
98
99 return nullptr;
100}
101
103{
105
106 for (auto* af : knownFormats)
107 extensions.addArray (af->getFileExtensions());
108
109 extensions.trim();
110 extensions.removeEmptyStrings();
111
112 for (auto& e : extensions)
113 e = (e.startsWithChar ('.') ? "*" : "*.") + e;
114
115 extensions.removeDuplicates (true);
116 return extensions.joinIntoString (";");
117}
118
119//==============================================================================
121{
122 // you need to actually register some formats before the manager can
123 // use them to open a file!
125
126 for (auto* af : knownFormats)
127 if (af->canHandleFile (file))
128 if (auto in = file.createInputStream())
129 if (auto* r = af->createReaderFor (in.release(), true))
130 return r;
131
132 return nullptr;
133}
134
136{
137 // you need to actually register some formats before the manager can
138 // use them to open a file!
140
141 if (audioFileStream != nullptr)
142 {
143 auto originalStreamPos = audioFileStream->getPosition();
144
145 for (auto* af : knownFormats)
146 {
147 if (auto* r = af->createReaderFor (audioFileStream.get(), false))
148 {
149 audioFileStream.release();
150 return r;
151 }
152
153 audioFileStream->setPosition (originalStreamPos);
154
155 // the stream that is passed-in must be capable of being repositioned so
156 // that all the formats can have a go at opening it.
157 jassert (audioFileStream->getPosition() == originalStreamPos);
158 }
159 }
160
161 return nullptr;
162}
163
164} // namespace juce
Reads and Writes AIFF format audio files.
AudioFormatReader * createReaderFor(const File &audioFile)
Searches through the known formats to try to create a suitable reader for this file.
AudioFormatManager()
Creates an empty format manager.
AudioFormat * getKnownFormat(int index) const
Returns one of the registered file formats.
void registerFormat(AudioFormat *newFormat, bool makeThisTheDefaultFormat)
Adds a format to the manager's list of available file types.
AudioFormat * getDefaultFormat() const
Returns the format which has been set as the default one.
AudioFormat * findFormatForFileExtension(const String &fileExtension) const
Looks for which of the known formats is listed as being for a given file extension.
int getNumKnownFormats() const
Returns the number of currently registered file formats.
String getWildcardForAllFormats() const
Returns a set of wildcards for file-matching that contains the extensions for all known formats.
void clearFormats()
Clears the list of known formats.
void registerBasicFormats()
Handy method to make it easy to register the formats that come with JUCE.
Reads samples from an audio file stream.
Subclasses of AudioFormat are used to read and write different audio file formats.
OSX and iOS only - This uses the AudioToolbox framework to read any audio format that the system has ...
Represents a local file or directory.
Definition juce_File.h:45
std::unique_ptr< FileInputStream > createInputStream() const
Creates a stream to read from this file.
Reads and writes the lossless-compression FLAC audio format.
Software-based MP3 decoding format (doesn't currently provide an encoder).
Reads and writes the Ogg-Vorbis audio format.
A special array for holding a list of strings.
void addArray(const StringArray &other, int startIndex=0, int numElementsToAdd=-1)
Appends some strings from another array to the end of this one.
The JUCE String class!
Definition juce_String.h:53
bool startsWithChar(juce_wchar character) const noexcept
Tests whether the string begins with a particular character.
Reads and Writes WAV format audio files.
Audio format which uses the Windows Media codecs (Windows only).
#define jassert(expression)
Platform-independent assertion macro.
#define jassertfalse
This will always cause an assertion failure.
JUCE Namespace.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
Definition juce_Memory.h:88