foobar2000 SDK  2015-08-03
file_info.h
Go to the documentation of this file.
1 struct replaygain_info
3 {
6 
7  enum {text_buffer_size = 16 };
9 
10  enum { peak_invalid = -1, gain_invalid = -1000 };
11 
12  static bool g_format_gain(float p_value,char p_buffer[text_buffer_size]);
13  static bool g_format_peak(float p_value,char p_buffer[text_buffer_size]);
14 
15  inline bool format_album_gain(char p_buffer[text_buffer_size]) const {return g_format_gain(m_album_gain,p_buffer);}
16  inline bool format_track_gain(char p_buffer[text_buffer_size]) const {return g_format_gain(m_track_gain,p_buffer);}
17  inline bool format_album_peak(char p_buffer[text_buffer_size]) const {return g_format_peak(m_album_peak,p_buffer);}
18  inline bool format_track_peak(char p_buffer[text_buffer_size]) const {return g_format_peak(m_track_peak,p_buffer);}
19 
20  void set_album_gain_text(const char * p_text,t_size p_text_len = pfc_infinite);
21  void set_track_gain_text(const char * p_text,t_size p_text_len = pfc_infinite);
22  void set_album_peak_text(const char * p_text,t_size p_text_len = pfc_infinite);
23  void set_track_peak_text(const char * p_text,t_size p_text_len = pfc_infinite);
24 
25  static bool g_is_meta_replaygain(const char * p_name,t_size p_name_len = pfc_infinite);
26  bool set_from_meta_ex(const char * p_name,t_size p_name_len,const char * p_value,t_size p_value_len);
27  inline bool set_from_meta(const char * p_name,const char * p_value) {return set_from_meta_ex(p_name,pfc_infinite,p_value,pfc_infinite);}
28 
29  inline bool is_album_gain_present() const {return m_album_gain != gain_invalid;}
30  inline bool is_track_gain_present() const {return m_track_gain != gain_invalid;}
31  inline bool is_album_peak_present() const {return m_album_peak != peak_invalid;}
32  inline bool is_track_peak_present() const {return m_track_peak != peak_invalid;}
33 
34  inline void remove_album_gain() {m_album_gain = gain_invalid;}
35  inline void remove_track_gain() {m_track_gain = gain_invalid;}
36  inline void remove_album_peak() {m_album_peak = peak_invalid;}
37  inline void remove_track_peak() {m_track_peak = peak_invalid;}
38 
40 
42 
43  static bool g_equal(const replaygain_info & item1,const replaygain_info & item2);
44 
45  void reset();
46 };
47 
49 public:
50  format_rg_gain(float val) {replaygain_info::g_format_gain(val, m_buffer);}
51 
52  operator const char * () const {return m_buffer;}
53 private:
55 };
56 
58 public:
59  format_rg_peak(float val) {replaygain_info::g_format_peak(val, m_buffer);}
60 
61  operator const char * () const {return m_buffer;}
62 private:
64 };
65 
66 inline bool operator==(const replaygain_info & item1,const replaygain_info & item2) {return replaygain_info::g_equal(item1,item2);}
67 inline bool operator!=(const replaygain_info & item1,const replaygain_info & item2) {return !replaygain_info::g_equal(item1,item2);}
68 
70 
71 
73 class NOVTABLE file_info {
74 public:
79  virtual double get_length() const = 0;
84  virtual void set_length(double p_length) = 0;
85 
87  virtual void set_replaygain(const replaygain_info & p_info) = 0;
89  virtual replaygain_info get_replaygain() const = 0;
90 
92  virtual t_size meta_get_count() const = 0;
94  virtual const char* meta_enum_name(t_size p_index) const = 0;
96  virtual t_size meta_enum_value_count(t_size p_index) const = 0;
98  virtual const char* meta_enum_value(t_size p_index,t_size p_value_number) const = 0;
100  virtual t_size meta_find_ex(const char * p_name,t_size p_name_length) const;
102  virtual t_size meta_set_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) = 0;
104  virtual void meta_insert_value_ex(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length) = 0;
106  virtual void meta_remove_mask(const bit_array & p_mask) = 0;
108  virtual void meta_reorder(const t_size * p_order) = 0;
110  virtual void meta_remove_values(t_size p_index,const bit_array & p_mask) = 0;
112  virtual void meta_modify_value_ex(t_size p_index,t_size p_value_index,const char * p_value,t_size p_value_length) = 0;
113 
115  virtual t_size info_get_count() const = 0;
117  virtual const char* info_enum_name(t_size p_index) const = 0;
119  virtual const char* info_enum_value(t_size p_index) const = 0;
121  virtual t_size info_set_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) = 0;
123  virtual void info_remove_mask(const bit_array & p_mask) = 0;
125  virtual t_size info_find_ex(const char * p_name,t_size p_name_length) const;
126 
128  virtual void copy(const file_info & p_source);//virtualized for performance reasons, can be faster in two-pass
130  virtual void copy_meta(const file_info & p_source);//virtualized for performance reasons, can be faster in two-pass
132  virtual void copy_info(const file_info & p_source);//virtualized for performance reasons, can be faster in two-pass
133 
134  bool meta_exists_ex(const char * p_name,t_size p_name_length) const;
135  void meta_remove_field_ex(const char * p_name,t_size p_name_length);
136  void meta_remove_index(t_size p_index);
137  void meta_remove_all();
138  void meta_remove_value(t_size p_index,t_size p_value);
139  const char * meta_get_ex(const char * p_name,t_size p_name_length,t_size p_index) const;
140  t_size meta_get_count_by_name_ex(const char * p_name,t_size p_name_length) const;
141  void meta_add_value_ex(t_size p_index,const char * p_value,t_size p_value_length);
142  t_size meta_add_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length);
143  t_size meta_calc_total_value_count() const;
144  bool meta_format(const char * p_name,pfc::string_base & p_out, const char * separator = ", ") const;
145  void meta_format_entry(t_size index, pfc::string_base & p_out, const char * separator = ", ") const;//same as meta_format but takes index instead of meta name.
146 
147 
148  bool info_exists_ex(const char * p_name,t_size p_name_length) const;
149  void info_remove_index(t_size p_index);
150  void info_remove_all();
151  bool info_remove_ex(const char * p_name,t_size p_name_length);
152  const char * info_get_ex(const char * p_name,t_size p_name_length) const;
153 
154  inline t_size meta_find(const char * p_name) const {return meta_find_ex(p_name,pfc_infinite);}
155  inline bool meta_exists(const char * p_name) const {return meta_exists_ex(p_name,pfc_infinite);}
156  inline void meta_remove_field(const char * p_name) {meta_remove_field_ex(p_name,pfc_infinite);}
157  inline t_size meta_set(const char * p_name,const char * p_value) {return meta_set_ex(p_name,pfc_infinite,p_value,pfc_infinite);}
158  inline void meta_insert_value(t_size p_index,t_size p_value_index,const char * p_value) {meta_insert_value_ex(p_index,p_value_index,p_value,pfc_infinite);}
159  inline void meta_add_value(t_size p_index,const char * p_value) {meta_add_value_ex(p_index,p_value,pfc_infinite);}
160  inline const char* meta_get(const char * p_name,t_size p_index) const {return meta_get_ex(p_name,pfc_infinite,p_index);}
161  inline t_size meta_get_count_by_name(const char * p_name) const {return meta_get_count_by_name_ex(p_name,pfc_infinite);}
162  inline t_size meta_add(const char * p_name,const char * p_value) {return meta_add_ex(p_name,pfc_infinite,p_value,pfc_infinite);}
163  inline void meta_modify_value(t_size p_index,t_size p_value_index,const char * p_value) {meta_modify_value_ex(p_index,p_value_index,p_value,pfc_infinite);}
164 
165 
166 
167  inline t_size info_set(const char * p_name,const char * p_value) {return info_set_ex(p_name,pfc_infinite,p_value,pfc_infinite);}
168  inline t_size info_find(const char * p_name) const {return info_find_ex(p_name,pfc_infinite);}
169  inline bool info_exists(const char * p_name) const {return info_exists_ex(p_name,pfc_infinite);}
170  inline bool info_remove(const char * p_name) {return info_remove_ex(p_name,pfc_infinite);}
171  inline const char * info_get(const char * p_name) const {return info_get_ex(p_name,pfc_infinite);}
172 
173  bool info_set_replaygain_ex(const char * p_name,t_size p_name_len,const char * p_value,t_size p_value_len);
174  inline bool info_set_replaygain(const char * p_name,const char * p_value) {return info_set_replaygain_ex(p_name,pfc_infinite,p_value,pfc_infinite);}
175  void info_set_replaygain_auto_ex(const char * p_name,t_size p_name_len,const char * p_value,t_size p_value_len);
176  inline void info_set_replaygain_auto(const char * p_name,const char * p_value) {info_set_replaygain_auto_ex(p_name,pfc_infinite,p_value,pfc_infinite);}
177 
178 
179 
180  void copy_meta_single(const file_info & p_source,t_size p_index);
181  void copy_info_single(const file_info & p_source,t_size p_index);
182  void copy_meta_single_by_name_ex(const file_info & p_source,const char * p_name,t_size p_name_length);
183  void copy_info_single_by_name_ex(const file_info & p_source,const char * p_name,t_size p_name_length);
184  inline void copy_meta_single_by_name(const file_info & p_source,const char * p_name) {copy_meta_single_by_name_ex(p_source,p_name,pfc_infinite);}
185  inline void copy_info_single_by_name(const file_info & p_source,const char * p_name) {copy_info_single_by_name_ex(p_source,p_name,pfc_infinite);}
186  void reset();
187  void reset_replaygain();
188  void copy_meta_single_rename_ex(const file_info & p_source,t_size p_index,const char * p_new_name,t_size p_new_name_length);
189  inline void copy_meta_single_rename(const file_info & p_source,t_size p_index,const char * p_new_name) {copy_meta_single_rename_ex(p_source,p_index,p_new_name,pfc_infinite);}
190  void overwrite_info(const file_info & p_source);
191  void overwrite_meta(const file_info & p_source);
192 
193  t_int64 info_get_int(const char * name) const;
194  t_int64 info_get_length_samples() const;
195  double info_get_float(const char * name) const;
196  void info_set_int(const char * name,t_int64 value);
197  void info_set_float(const char * name,double value,unsigned precision,bool force_sign = false,const char * unit = 0);
198  void info_set_replaygain_track_gain(float value);
199  void info_set_replaygain_album_gain(float value);
200  void info_set_replaygain_track_peak(float value);
201  void info_set_replaygain_album_peak(float value);
202 
203  inline t_int64 info_get_bitrate_vbr() const {return info_get_int("bitrate_dynamic");}
204  inline void info_set_bitrate_vbr(t_int64 val) {info_set_int("bitrate_dynamic",val);}
205  inline t_int64 info_get_bitrate() const {return info_get_int("bitrate");}
206  inline void info_set_bitrate(t_int64 val) {info_set_int("bitrate",val);}
207 
208  void info_set_wfx_chanMask(uint32_t val);
209  uint32_t info_get_wfx_chanMask() const;
210 
211  bool is_encoding_lossy() const;
212 
213 
214  void info_calculate_bitrate(t_filesize p_filesize,double p_length);
215 
216  unsigned info_get_decoded_bps() const;//what bps the stream originally was (before converting to audio_sample), 0 if unknown
217 
218 private:
219  void merge(const pfc::list_base_const_t<const file_info*> & p_sources);
220 public:
221 
222  void _set_tag(const file_info & tag);
223  void _add_tag(const file_info & otherTag);
224 
225  void merge_fallback(const file_info & fallback);
226 
227  bool are_meta_fields_identical(t_size p_index1,t_size p_index2) const;
228 
229  inline const file_info & operator=(const file_info & p_source) {copy(p_source);return *this;}
230 
231  static bool g_is_meta_equal(const file_info & p_item1,const file_info & p_item2);
232  static bool g_is_meta_equal_debug(const file_info & p_item1,const file_info & p_item2);
233  static bool g_is_info_equal(const file_info & p_item1,const file_info & p_item2);
234 
236  t_size __meta_add_unsafe_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) {return meta_set_nocheck_ex(p_name,p_name_length,p_value,p_value_length);}
238  t_size __meta_add_unsafe(const char * p_name,const char * p_value) {return meta_set_nocheck_ex(p_name,pfc_infinite,p_value,pfc_infinite);}
239 
241  t_size __info_add_unsafe_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) {return info_set_nocheck_ex(p_name,p_name_length,p_value,p_value_length);}
243  t_size __info_add_unsafe(const char * p_name,const char * p_value) {return info_set_nocheck_ex(p_name,pfc_infinite,p_value,pfc_infinite);}
244 
245  void _copy_meta_single_nocheck(const file_info & p_source,t_size p_index) {copy_meta_single_nocheck(p_source, p_index);}
246 
247  static bool g_is_valid_field_name(const char * p_name,t_size p_length = pfc_infinite);
248  //typedef pfc::comparator_stricmp_ascii field_name_comparator;
250 
251  static bool field_name_equals(const char * n1, const char * n2) {return field_name_comparator::compare(n1, n2) == 0;}
252 
253  void to_console() const;
254  void to_formatter(pfc::string_formatter&) const;
255  static bool field_is_person(const char * fieldName);
256  static bool field_is_title(const char * fieldName);
257 
258  void to_stream( stream_writer * stream, abort_callback & abort ) const;
259  void from_stream( stream_reader * stream, abort_callback & abort );
260  void from_mem( const void * memPtr, size_t memSize);
261 
264  audio_chunk::spec_t audio_chunk_spec() const;
265 protected:
268  void copy_meta_single_nocheck(const file_info & p_source,t_size p_index);
269  void copy_info_single_nocheck(const file_info & p_source,t_size p_index);
270  void copy_meta_single_by_name_nocheck_ex(const file_info & p_source,const char * p_name,t_size p_name_length);
271  void copy_info_single_by_name_nocheck_ex(const file_info & p_source,const char * p_name,t_size p_name_length);
272  inline void copy_meta_single_by_name_nocheck(const file_info & p_source,const char * p_name) {copy_meta_single_by_name_nocheck_ex(p_source,p_name,pfc_infinite);}
273  inline void copy_info_single_by_name_nocheck(const file_info & p_source,const char * p_name) {copy_info_single_by_name_nocheck_ex(p_source,p_name,pfc_infinite);}
274 
275  virtual t_size meta_set_nocheck_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) = 0;
276  virtual t_size info_set_nocheck_ex(const char * p_name,t_size p_name_length,const char * p_value,t_size p_value_length) = 0;
277  inline t_size meta_set_nocheck(const char * p_name,const char * p_value) {return meta_set_nocheck_ex(p_name,pfc_infinite,p_value,pfc_infinite);}
278  inline t_size info_set_nocheck(const char * p_name,const char * p_value) {return info_set_nocheck_ex(p_name,pfc_infinite,p_value,pfc_infinite);}
279 };
void info_set_bitrate(t_int64 val)
Definition: file_info.h:206
void meta_modify_value(t_size p_index, t_size p_value_index, const char *p_value)
Definition: file_info.h:163
void set_album_gain_text(const char *p_text, t_size p_text_len=pfc_infinite)
replaygain_info::t_text_buffer m_buffer
Definition: file_info.h:54
void copy_meta_single_rename(const file_info &p_source, t_size p_index, const char *p_new_name)
Definition: file_info.h:189
void remove_album_gain()
Definition: file_info.h:34
void info_set_bitrate_vbr(t_int64 val)
Definition: file_info.h:204
bool is_track_peak_present() const
Definition: file_info.h:32
t_int64 info_get_bitrate_vbr() const
Definition: file_info.h:203
t_size __info_add_unsafe_ex(const char *p_name, t_size p_name_length, const char *p_value, t_size p_value_length)
Unsafe - does not check whether the field already exists and will result in duplicates if it does - c...
Definition: file_info.h:241
bool format_track_gain(char p_buffer[text_buffer_size]) const
Definition: file_info.h:16
void remove_album_peak()
Definition: file_info.h:36
bool set_from_meta(const char *p_name, const char *p_value)
Definition: file_info.h:27
float m_track_gain
Definition: file_info.h:4
t_size meta_add(const char *p_name, const char *p_value)
Definition: file_info.h:162
bool info_exists(const char *p_name) const
Definition: file_info.h:169
static bool g_format_peak(float p_value, char p_buffer[text_buffer_size])
float m_album_peak
Definition: file_info.h:5
Bit array interface class, constant version (you can only retrieve values). Range of valid indexes d...
Definition: bit_array.h:6
int compare(t1 const &p1, t2 const &p2)
Definition: pathUtils.h:29
const char * info_get(const char *p_name) const
Definition: file_info.h:171
void copy_meta_single_by_name(const file_info &p_source, const char *p_name)
Definition: file_info.h:184
bool info_remove(const char *p_name)
Definition: file_info.h:170
static bool g_equal(const replaygain_info &item1, const replaygain_info &item2)
Definition: file_info.cpp:355
format_rg_peak(float val)
Definition: file_info.h:59
static const replaygain_info replaygain_info_invalid
Definition: file_info.h:69
void meta_add_value(t_size p_index, const char *p_value)
Definition: file_info.h:159
bool format_album_peak(char p_buffer[text_buffer_size]) const
Definition: file_info.h:17
Structure containing ReplayGain scan results from some playable object, also providing various helper...
Definition: file_info.h:2
bool info_set_replaygain(const char *p_name, const char *p_value)
Definition: file_info.h:174
replaygain_info::t_text_buffer m_buffer
Definition: file_info.h:63
t_size meta_set_nocheck(const char *p_name, const char *p_value)
Definition: file_info.h:277
t_size __meta_add_unsafe(const char *p_name, const char *p_value)
Unsafe - does not check whether the field already exists and will result in duplicates if it does - c...
Definition: file_info.h:238
void copy_meta_single_by_name_nocheck(const file_info &p_source, const char *p_name)
Definition: file_info.h:272
const char * meta_get(const char *p_name, t_size p_index) const
Definition: file_info.h:160
Main interface class for information about some playable object.
Definition: file_info.h:73
void _copy_meta_single_nocheck(const file_info &p_source, t_size p_index)
Definition: file_info.h:245
void meta_remove_field(const char *p_name)
Definition: file_info.h:156
size_t t_size
Definition: int_types.h:48
string8_fastalloc string_formatter
Definition: string_base.h:615
t_size info_set_nocheck(const char *p_name, const char *p_value)
Definition: file_info.h:278
static bool g_is_meta_replaygain(const char *p_name, t_size p_name_len=pfc_infinite)
static bool g_format_gain(float p_value, char p_buffer[text_buffer_size])
t_size __meta_add_unsafe_ex(const char *p_name, t_size p_name_length, const char *p_value, t_size p_value_length)
Unsafe - does not check whether the field already exists and will result in duplicates if it does - c...
Definition: file_info.h:236
bool format_track_peak(char p_buffer[text_buffer_size]) const
Definition: file_info.h:18
t_size __info_add_unsafe(const char *p_name, const char *p_value)
Unsafe - does not check whether the field already exists and will result in duplicates if it does - c...
Definition: file_info.h:243
t_size get_value_count()
t_size info_set(const char *p_name, const char *p_value)
Definition: file_info.h:167
void set_album_peak_text(const char *p_text, t_size p_text_len=pfc_infinite)
~file_info()
Definition: file_info.h:267
void set_track_peak_text(const char *p_text, t_size p_text_len=pfc_infinite)
bool operator==(const replaygain_info &item1, const replaygain_info &item2)
Definition: file_info.h:66
t_int64 info_get_bitrate() const
Definition: file_info.h:205
bool meta_exists(const char *p_name) const
Definition: file_info.h:155
t_size meta_get_count_by_name(const char *p_name) const
Definition: file_info.h:161
void meta_insert_value(t_size p_index, t_size p_value_index, const char *p_value)
Definition: file_info.h:158
void copy_info_single_by_name(const file_info &p_source, const char *p_name)
Definition: file_info.h:185
static replaygain_info g_merge(replaygain_info r1, replaygain_info r2)
t_size info_find(const char *p_name) const
Definition: file_info.h:168
bool format_album_gain(char p_buffer[text_buffer_size]) const
Definition: file_info.h:15
t_uint64 t_filesize
Type used for file size related variables.
Definition: filesystem.h:8
static bool field_name_equals(const char *n1, const char *n2)
Definition: file_info.h:251
bool is_album_peak_present() const
Definition: file_info.h:31
bool is_track_gain_present() const
Definition: file_info.h:30
format_rg_gain(float val)
Definition: file_info.h:50
bool set_from_meta_ex(const char *p_name, t_size p_name_len, const char *p_value, t_size p_value_len)
bool operator!=(const replaygain_info &item1, const replaygain_info &item2)
Definition: file_info.h:67
float m_album_gain
Definition: file_info.h:4
void remove_track_gain()
Definition: file_info.h:35
t_size meta_set(const char *p_name, const char *p_value)
Definition: file_info.h:157
bool is_album_gain_present() const
Definition: file_info.h:29
void remove_track_peak()
Definition: file_info.h:37
This is free and unencumbered software released into the public domain Anyone is free to copy
Definition: pfc-license.txt:3
float m_track_peak
Definition: file_info.h:5
const file_info & operator=(const file_info &p_source)
Definition: file_info.h:229
void info_set_replaygain_auto(const char *p_name, const char *p_value)
Definition: file_info.h:176
pfc::string::comparatorCaseInsensitiveASCII field_name_comparator
Definition: file_info.h:249
void copy_info_single_by_name_nocheck(const file_info &p_source, const char *p_name)
Definition: file_info.h:273
void set_track_gain_text(const char *p_text, t_size p_text_len=pfc_infinite)
t_size meta_find(const char *p_name) const
Definition: file_info.h:154
char t_text_buffer[text_buffer_size]
Definition: file_info.h:8
int64_t t_int64
Definition: int_types.h:2