forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileFormats.h
161 lines (130 loc) · 4.59 KB
/
FileFormats.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/**********************************************************************
Sneedacity: A Digital Audio Editor
FileFormats.h
Dominic Mazzoni
**********************************************************************/
#ifndef __SNEEDACITY_FILE_FORMATS__
#define __SNEEDACITY_FILE_FORMATS__
#include "sneedacity/Types.h"
#include "Identifier.h"
//#include <mutex>
#include <memory>
#include "sndfile.h"
class ChoiceSetting;
class wxString;
//
// enumerating headers
//
/** @brief Get the number of container formats supported by libsndfile
*
* Uses SFC_GET_FORMAT_MAJOR_COUNT in sf_command interface */
SNEEDACITY_DLL_API
int sf_num_headers();
/** @brief Get the name of a container format from libsndfile
*
* Uses SFC_GET_FORMAT_MAJOR in the sf_command() interface. Resulting C string
* from libsndfile is converted to a wxString
* @param format_num The libsndfile format number for the container format
* required
*/
SNEEDACITY_DLL_API
wxString sf_header_index_name(int format_num);
SNEEDACITY_DLL_API
unsigned int sf_header_index_to_type(int format_num);
//
// enumerating encodings
//
/** @brief Get the number of data encodings libsndfile supports (in any
* container or none */
SNEEDACITY_DLL_API
int sf_num_encodings();
/** @brief Get the string name of the data encoding of the requested format
*
* uses SFC_GET_FORMAT_SUBTYPE */
SNEEDACITY_DLL_API
wxString sf_encoding_index_name(int encoding_num);
SNEEDACITY_DLL_API
unsigned int sf_encoding_index_to_subtype(int encoding_num);
//
// getting info about an actual SF format
//
/** @brief Get the string name of the specified container format
*
* AND format with SF_FORMAT_TYPEMASK to get only the container format and
* then use SFC_GET_FORMAT_INFO to get the description
* @param format the libsndfile format to get the name for (only the container
* part is used) */
SNEEDACITY_DLL_API
wxString sf_header_name(int format);
/** @brief Get an abbreviated form of the string name of the specified format
*
* Do sf_header_name() then truncate the string at the first space in the name
* to get just the first word of the format name.
* @param format the libsndfile format to get the name for (only the container
* part is used) */
SNEEDACITY_DLL_API
wxString sf_header_shortname(int format);
/** @brief Get the most common file extension for the given format
*
* AND the given format with SF_FORMAT_TYPEMASK to get just the container
* format, then retrieve the most common extension using SFC_GET_FORMAT_INFO.
* @param format the libsndfile format to get the name for (only the container
* part is used) */
SNEEDACITY_DLL_API
wxString sf_header_extension(int format);
/** @brief Get the string name of the specified data encoding
*
* AND encoding_num with SF_FORMAT_SUBMASK to get only the data encoding and
* then use SFC_GET_FORMAT_INFO to get the description
* @param encoding_num the libsndfile encoding to get the name for (only the
* data encoding is used) */
wxString sf_encoding_name(int encoding_num);
//
// simple formats
//
int sf_num_simple_formats();
SF_FORMAT_INFO *sf_simple_format(int i);
//
// other utility functions
//
SNEEDACITY_DLL_API
bool sf_subtype_more_than_16_bits(unsigned int format);
SNEEDACITY_DLL_API
bool sf_subtype_is_integer(unsigned int format);
SNEEDACITY_DLL_API
int sf_subtype_bytes_per_sample(unsigned int format);
SNEEDACITY_DLL_API
//! Choose the narrowest value in the sampleFormat enumeration for a given libsndfile format
sampleFormat sf_subtype_to_effective_format(unsigned int format);
SNEEDACITY_DLL_API
extern FileExtensions sf_get_all_extensions();
wxString sf_normalize_name(const char *name);
// This function wrapper uses a mutex to serialize calls to the SndFile library.
// PRL: Keeping this in a comment, but with Unitary, the only remaining uses
// of libsndfile should be in import/export and so are on the main thread only
//extern std::mutex libSndFileMutex;
template<typename R, typename F, typename... Args>
inline R SFCall(F fun, Args&&... args)
{
//std::lock_guard<std::mutex> guard{ libSndFileMutex };
return fun(std::forward<Args>(args)...);
}
//RAII for SNDFILE*
struct SNEEDACITY_DLL_API SFFileCloser { int operator () (SNDFILE*) const; };
struct SFFile : public std::unique_ptr<SNDFILE, ::SFFileCloser>
{
SFFile() = default;
SFFile( SFFile &&that )
: std::unique_ptr<SNDFILE, ::SFFileCloser>( std::move( that ) )
{}
// Close explicitly, not ignoring return values.
int close()
{
auto result = get_deleter() ( get() );
release();
return result;
}
};
extern ChoiceSetting FileFormatsCopyOrEditSetting;
extern ChoiceSetting FileFormatsSaveWithDependenciesSetting;
#endif