summaryrefslogtreecommitdiff
path: root/src/libaudtag/ape/ape.cc
diff options
context:
space:
mode:
authorMateusz Łukasik <mati75@linuxmint.pl>2016-02-05 21:36:07 +0100
committerMateusz Łukasik <mati75@linuxmint.pl>2016-02-05 21:36:07 +0100
commit7f08dcfc78675bed63f962f6d01cfb18264e12c7 (patch)
treedb54c9dc0279b43c1eedea09512ec60ecb3c94e9 /src/libaudtag/ape/ape.cc
parentb541fedc97ad4ed5e658ce34ee50c74ad756f330 (diff)
Imported Upstream version 3.7.1
Diffstat (limited to 'src/libaudtag/ape/ape.cc')
-rw-r--r--src/libaudtag/ape/ape.cc64
1 files changed, 9 insertions, 55 deletions
diff --git a/src/libaudtag/ape/ape.cc b/src/libaudtag/ape/ape.cc
index c8657b4..165fed4 100644
--- a/src/libaudtag/ape/ape.cc
+++ b/src/libaudtag/ape/ape.cc
@@ -21,7 +21,6 @@
* - Support updating files that have their tag at the beginning?
*/
-#include <limits.h>
#include <stdlib.h>
#include <string.h>
@@ -241,57 +240,12 @@ static Index<ValuePair> ape_read_items (VFSFile & handle)
return list;
}
-static void parse_gain_text (const char * text, int * value, int * unit)
+bool APETagModule::read_tag (VFSFile & handle, Tuple * ptuple, Index<char> * image)
{
- int sign = 1;
+ if (! ptuple)
+ return true; // nothing to do
- * value = 0;
- * unit = 1;
-
- if (* text == '-')
- {
- sign = -1;
- text ++;
- }
-
- while (* text >= '0' && * text <= '9')
- {
- * value = * value * 10 + (* text - '0');
- text ++;
- }
-
- if (* text == '.')
- {
- text ++;
-
- while (* text >= '0' && * text <= '9' && * value < INT_MAX / 10)
- {
- * value = * value * 10 + (* text - '0');
- * unit = * unit * 10;
- text ++;
- }
- }
-
- * value = * value * sign;
-}
-
-static void set_gain_info (Tuple & tuple, Tuple::Field field,
- Tuple::Field unit_field, const char * text)
-{
- int value, unit;
-
- parse_gain_text (text, & value, & unit);
-
- if (tuple.get_value_type (unit_field) == Tuple::Int)
- value = value * (int64_t) tuple.get_int (unit_field) / unit;
- else
- tuple.set_int (unit_field, unit);
-
- tuple.set_int (field, value);
-}
-
-bool APETagModule::read_tag (Tuple & tuple, VFSFile & handle)
-{
+ Tuple & tuple = * ptuple;
Index<ValuePair> list = ape_read_items (handle);
for (const ValuePair & pair : list)
@@ -311,13 +265,13 @@ bool APETagModule::read_tag (Tuple & tuple, VFSFile & handle)
else if (! strcmp (pair.key, "Year"))
tuple.set_int (Tuple::Year, atoi (pair.value));
else if (! strcmp_nocase (pair.key, "REPLAYGAIN_TRACK_GAIN"))
- set_gain_info (tuple, Tuple::TrackGain, Tuple::GainDivisor, pair.value);
+ tuple.set_gain (Tuple::TrackGain, Tuple::GainDivisor, pair.value);
else if (! strcmp_nocase (pair.key, "REPLAYGAIN_TRACK_PEAK"))
- set_gain_info (tuple, Tuple::TrackPeak, Tuple::PeakDivisor, pair.value);
+ tuple.set_gain (Tuple::TrackPeak, Tuple::PeakDivisor, pair.value);
else if (! strcmp_nocase (pair.key, "REPLAYGAIN_ALBUM_GAIN"))
- set_gain_info (tuple, Tuple::AlbumGain, Tuple::GainDivisor, pair.value);
+ tuple.set_gain (Tuple::AlbumGain, Tuple::GainDivisor, pair.value);
else if (! strcmp_nocase (pair.key, "REPLAYGAIN_ALBUM_PEAK"))
- set_gain_info (tuple, Tuple::AlbumPeak, Tuple::PeakDivisor, pair.value);
+ tuple.set_gain (Tuple::AlbumPeak, Tuple::PeakDivisor, pair.value);
}
return true;
@@ -395,7 +349,7 @@ static bool write_header (int data_length, int items, bool is_header,
return handle.fwrite (& header, 1, sizeof (APEHeader)) == sizeof (APEHeader);
}
-bool APETagModule::write_tag (const Tuple & tuple, VFSFile & handle)
+bool APETagModule::write_tag (VFSFile & handle, const Tuple & tuple)
{
Index<ValuePair> list = ape_read_items (handle);
APEHeader header;