AudioStreamWAV: Inline tag remap inside load
This commit is contained in:
@ -485,10 +485,6 @@ Dictionary AudioStreamWAV::get_tags() const {
|
||||
return tags;
|
||||
}
|
||||
|
||||
HashMap<String, String>::ConstIterator AudioStreamWAV::remap_tag_id(const String &p_tag_id) {
|
||||
return tag_id_remaps.find(p_tag_id);
|
||||
}
|
||||
|
||||
double AudioStreamWAV::get_length() const {
|
||||
int len = data_bytes;
|
||||
switch (format) {
|
||||
@ -1146,16 +1142,37 @@ Ref<AudioStreamWAV> AudioStreamWAV::load_from_buffer(const Vector<uint8_t> &p_st
|
||||
sample->set_loop_end(loop_end);
|
||||
sample->set_stereo(format_channels == 2);
|
||||
|
||||
Dictionary tag_dictionary;
|
||||
for (const KeyValue<String, String> &E : tag_map) {
|
||||
HashMap<String, String>::ConstIterator remap = sample->remap_tag_id(E.key);
|
||||
if (remap) {
|
||||
tag_map.replace_key(E.key, remap->value);
|
||||
}
|
||||
if (!tag_map.is_empty()) {
|
||||
// Used to make the metadata tags more unified across different AudioStreams.
|
||||
// See https://www.recordingblogs.com/wiki/list-chunk-of-a-wave-file
|
||||
HashMap<String, String> tag_id_remaps;
|
||||
tag_id_remaps.reserve(15);
|
||||
tag_id_remaps["IARL"] = "location";
|
||||
tag_id_remaps["IART"] = "artist";
|
||||
tag_id_remaps["ICMS"] = "organization";
|
||||
tag_id_remaps["ICMT"] = "comments";
|
||||
tag_id_remaps["ICOP"] = "copyright";
|
||||
tag_id_remaps["ICRD"] = "date";
|
||||
tag_id_remaps["IGNR"] = "genre";
|
||||
tag_id_remaps["IKEY"] = "keywords";
|
||||
tag_id_remaps["IMED"] = "medium";
|
||||
tag_id_remaps["INAM"] = "title";
|
||||
tag_id_remaps["IPRD"] = "album";
|
||||
tag_id_remaps["ISBJ"] = "description";
|
||||
tag_id_remaps["ISFT"] = "software";
|
||||
tag_id_remaps["ITRK"] = "tracknumber";
|
||||
Dictionary tag_dictionary;
|
||||
for (const KeyValue<String, String> &E : tag_map) {
|
||||
HashMap<String, String>::ConstIterator remap = tag_id_remaps.find(E.key);
|
||||
String tag_key = E.key;
|
||||
if (remap) {
|
||||
tag_key = remap->value;
|
||||
}
|
||||
|
||||
tag_dictionary[E.key] = E.value;
|
||||
tag_dictionary[tag_key] = E.value;
|
||||
}
|
||||
sample->set_tags(tag_dictionary);
|
||||
}
|
||||
sample->set_tags(tag_dictionary);
|
||||
|
||||
return sample;
|
||||
}
|
||||
@ -1215,22 +1232,3 @@ void AudioStreamWAV::_bind_methods() {
|
||||
BIND_ENUM_CONSTANT(LOOP_PINGPONG);
|
||||
BIND_ENUM_CONSTANT(LOOP_BACKWARD);
|
||||
}
|
||||
|
||||
AudioStreamWAV::AudioStreamWAV() {
|
||||
// Used to make the metadata tags more unified across different AudioStreams.
|
||||
// See https://www.recordingblogs.com/wiki/list-chunk-of-a-wave-file
|
||||
tag_id_remaps["IARL"] = "location";
|
||||
tag_id_remaps["IART"] = "artist";
|
||||
tag_id_remaps["ICMS"] = "organization";
|
||||
tag_id_remaps["ICMT"] = "comments";
|
||||
tag_id_remaps["ICOP"] = "copyright";
|
||||
tag_id_remaps["ICRD"] = "date";
|
||||
tag_id_remaps["IGNR"] = "genre";
|
||||
tag_id_remaps["IKEY"] = "keywords";
|
||||
tag_id_remaps["IMED"] = "medium";
|
||||
tag_id_remaps["INAM"] = "title";
|
||||
tag_id_remaps["IPRD"] = "album";
|
||||
tag_id_remaps["ISBJ"] = "description";
|
||||
tag_id_remaps["ISFT"] = "software";
|
||||
tag_id_remaps["ITRK"] = "tracknumber";
|
||||
}
|
||||
|
||||
@ -124,7 +124,6 @@ private:
|
||||
LocalVector<uint8_t> data;
|
||||
uint32_t data_bytes = 0;
|
||||
|
||||
HashMap<String, String> tag_id_remaps;
|
||||
Dictionary tags;
|
||||
|
||||
protected:
|
||||
@ -155,8 +154,6 @@ public:
|
||||
void set_tags(const Dictionary &p_tags);
|
||||
virtual Dictionary get_tags() const override;
|
||||
|
||||
HashMap<String, String>::ConstIterator remap_tag_id(const String &p_tag_id);
|
||||
|
||||
virtual double get_length() const override; //if supported, otherwise return 0
|
||||
|
||||
virtual bool is_monophonic() const override;
|
||||
@ -292,8 +289,6 @@ public:
|
||||
dst_ptr += qoa_encode_frame(data16.ptr(), p_desc, frame_len, dst_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
AudioStreamWAV();
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(AudioStreamWAV::Format)
|
||||
|
||||
Reference in New Issue
Block a user