foobar2000 SDK  2015-08-03
meta_table_builder.h
Go to the documentation of this file.
2 public:
3  _meta_table_enum_wrapper(file_info & p_info) : m_info(p_info) {}
4  template<typename t_values>
5  void operator() (const char * p_name,const t_values & p_values) {
6  t_size index = ~0;
7  for(typename t_values::const_iterator iter = p_values.first(); iter.is_valid(); ++iter) {
8  if (index == ~0) index = m_info.__meta_add_unsafe(p_name,*iter);
9  else m_info.meta_add_value(index,*iter);
10  }
11  }
12 private:
14 };
15 
17 public:
19  template<typename t_values>
20  void operator() (const char * p_name,const t_values & p_values) {
21  if (p_values.get_count() > 0) {
22  if (!m_info.info_set_replaygain(p_name, *p_values.first())) {
23  t_size index = ~0;
24  for(typename t_values::const_iterator iter = p_values.first(); iter.is_valid(); ++iter) {
25  if (index == ~0) index = m_info.__meta_add_unsafe(p_name,*iter);
26  else m_info.meta_add_value(index,*iter);
27  }
28  }
29  }
30  }
31 private:
33 };
34 
37 public:
40 
41  t_content & content() {return m_data;}
42  t_content const & content() const {return m_data;}
43 
44  void add(const char * p_name,const char * p_value,t_size p_value_len = ~0) {
46  _add(p_name).insert_last()->set_string(p_value,p_value_len);
47  }
48  }
49 
50  void remove(const char * p_name) {
51  m_data.remove(p_name);
52  }
53  void set(const char * p_name,const char * p_value,t_size p_value_len = ~0) {
55  t_entry & entry = _add(p_name);
56  entry.remove_all();
57  entry.insert_last()->set_string(p_value,p_value_len);
58  }
59  }
60  t_entry & add(const char * p_name) {
61  if (!file_info::g_is_valid_field_name(p_name)) uBugCheck();//we return a reference, nothing smarter to do
62  return _add(p_name);
63  }
64  void deduplicate(const char * name) {
65  t_entry * e;
66  if (!m_data.query_ptr(name, e)) return;
68  for(t_entry::iterator iter = e->first(); iter.is_valid(); ) {
69  t_entry::iterator next = iter; ++next;
70  const char * v = *iter;
71  if (!found.add_item_check(v)) e->remove(iter);
72  iter = next;
73  }
74  }
75  void keep_one(const char * name) {
76  t_entry * e;
77  if (!m_data.query_ptr(name, e)) return;
78  while(e->get_count() > 1) e->remove(e->last());
79  }
81  deduplicate("album artist");
82  deduplicate("publisher");
83  keep_one("totaltracks");
84  keep_one("totaldiscs");
85  }
86  void finalize(file_info & p_info) const {
87  p_info.meta_remove_all();
88  _meta_table_enum_wrapper e(p_info);
89  m_data.enumerate(e);
90  }
91  void finalize_withRG(file_info & p_info) const {
94  m_data.enumerate(e);
95  }
96 
97  void from_info(const file_info & p_info) {
98  m_data.remove_all();
99  from_info_overwrite(p_info);
100  }
101  void from_info_withRG(const file_info & p_info) {
102  m_data.remove_all();
103  from_info_overwrite(p_info);
104  from_RG_overwrite(p_info.get_replaygain());
105  }
108  if (info.format_album_gain(buffer)) set("replaygain_album_gain", buffer);
109  if (info.format_track_gain(buffer)) set("replaygain_track_gain", buffer);
110  if (info.format_album_peak(buffer)) set("replaygain_album_peak", buffer);
111  if (info.format_track_peak(buffer)) set("replaygain_track_peak", buffer);
112  }
113  void from_info_overwrite(const file_info & p_info) {
114  for(t_size metawalk = 0, metacount = p_info.meta_get_count(); metawalk < metacount; ++metawalk ) {
115  const t_size valuecount = p_info.meta_enum_value_count(metawalk);
116  if (valuecount > 0) {
117  t_entry & entry = add(p_info.meta_enum_name(metawalk));
118  entry.remove_all();
119  for(t_size valuewalk = 0; valuewalk < valuecount; ++valuewalk) {
120  entry.insert_last(p_info.meta_enum_value(metawalk,valuewalk));
121  }
122  }
123  }
124  }
125  void reset() {m_data.remove_all();}
126 
128  static const char cmp[] = "itunescompilation";
129  if (m_data.have_item(cmp)) {
130  // m_data.remove(cmp);
131  if (!m_data.have_item("album artist")) add("album artist", "Various Artists");
132  }
133  }
134 private:
135 
136  t_entry & _add(const char * p_name) {
137  return m_data.find_or_add(p_name);
138  }
139 
140  t_content m_data;
141 };
void from_RG_overwrite(replaygain_info info)
bool add_item_check(t_param const &item)
Returns true when the list has been altered, false when the item was already present before...
Definition: avltree.h:393
_meta_table_enum_wrapper_RG(file_info &p_info)
bool format_track_gain(char p_buffer[text_buffer_size]) const
Definition: file_info.h:16
pfc::chain_list_v2_t< pfc::string8 > t_entry
pfc::map_t< pfc::string8, t_entry, file_info::field_name_comparator > t_content
void info(const char *p_message)
Definition: console.cpp:4
virtual t_size meta_enum_value_count(t_size p_index) const =0
Retrieves count of values in metadata entry of specified index. The value is always equal to or great...
Differences between chain_list_v2_t<> and old chain_list_t<>: Iterators pointing to removed items as...
Definition: chain_list_v2.h:26
t_entry & _add(const char *p_name)
virtual const char * meta_enum_value(t_size p_index, t_size p_value_number) const =0
Retrieves specified value from specified metadata entry. Return value is a null-terminated UTF-8 enco...
static const replaygain_info replaygain_info_invalid
Definition: file_info.h:69
bool is_valid() const
Definition: iterators.h:24
void meta_add_value(t_size p_index, const char *p_value)
Definition: file_info.h:159
Purpose: building a file_info metadata table from loose input without search-for-existing-entry bottl...
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
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 remove(const_iterator const &p_iter)
Definition: chain_list_v2.h:73
void from_info_withRG(const file_info &p_info)
t_size get_count() const
Definition: chain_list_v2.h:61
Main interface class for information about some playable object.
Definition: file_info.h:73
void from_info(const file_info &p_info)
void operator()(const char *p_name, const t_values &p_values)
size_t t_size
Definition: int_types.h:48
virtual t_size meta_get_count() const =0
Retrieves count of metadata entries.
void finalize_withRG(file_info &p_info) const
void finalize(file_info &p_info) const
bool format_track_peak(char p_buffer[text_buffer_size]) const
Definition: file_info.h:18
void keep_one(const char *name)
virtual void set_replaygain(const replaygain_info &p_info)=0
Sets ReplayGain information.
void deduplicate(const char *name)
void add(const char *p_name, const char *p_value, t_size p_value_len=~0)
_meta_table_enum_wrapper(file_info &p_info)
bool format_album_gain(char p_buffer[text_buffer_size]) const
Definition: file_info.h:15
void meta_remove_all()
Definition: file_info.cpp:35
t_content const & content() const
static bool g_is_valid_field_name(const char *p_name, t_size p_length=pfc_infinite)
Definition: file_info.cpp:498
virtual replaygain_info get_replaygain() const =0
Retrieves ReplayGain information.
PFC_NORETURN void SHARED_EXPORT uBugCheck()
t_entry & add(const char *p_name)
void from_info_overwrite(const file_info &p_info)
char t_text_buffer[text_buffer_size]
Definition: file_info.h:8
virtual const char * meta_enum_name(t_size p_index) const =0
Retrieves the name of metadata entry of specified index. Return value is a null-terminated UTF-8 enco...