| 253 | | if(NO == frameList.isEmpty() && NULL != (relativeVolume = dynamic_cast<TagLib::ID3v2::RelativeVolumeFrame *>(frameList.front()))) { |
| 254 | | |
| 255 | | // Attempt to use the master volume if present |
| 256 | | TagLib::List<TagLib::ID3v2::RelativeVolumeFrame::ChannelType> channels = relativeVolume->channels(); |
| 257 | | TagLib::ID3v2::RelativeVolumeFrame::ChannelType channelType = TagLib::ID3v2::RelativeVolumeFrame::MasterVolume; |
| 258 | | |
| 259 | | // Fall back on whatever else exists in the frame |
| 260 | | if(NO == channels.contains(TagLib::ID3v2::RelativeVolumeFrame::MasterVolume)) |
| 261 | | channelType = channels.front(); |
| 262 | | |
| 263 | | float volumeAdjustment = relativeVolume->volumeAdjustment(channelType); |
| 264 | | |
| 265 | | if(0 != volumeAdjustment) { |
| 266 | | [metadataDictionary setValue:[NSNumber numberWithFloat:volumeAdjustment] forKey:ReplayGainTrackGainKey]; |
| 267 | | foundReplayGain = YES; |
| 268 | | } |
| 269 | | } |
| | 252 | |
| | 253 | TagLib::ID3v2::FrameList::Iterator frameIterator; |
| | 254 | for(frameIterator = frameList.begin(); frameIterator != frameList.end(); ++frameIterator) { |
| | 255 | TagLib::ID3v2::RelativeVolumeFrame *relativeVolume = dynamic_cast<TagLib::ID3v2::RelativeVolumeFrame *>(*frameIterator); |
| | 256 | if(NULL == relativeVolume) |
| | 257 | continue; |
| | 258 | |
| | 259 | if(TagLib::String("replaygain_track_gain", TagLib::String::Latin1) == relativeVolume->identification()) { |
| | 260 | // Attempt to use the master volume if present |
| | 261 | TagLib::List<TagLib::ID3v2::RelativeVolumeFrame::ChannelType> channels = relativeVolume->channels(); |
| | 262 | TagLib::ID3v2::RelativeVolumeFrame::ChannelType channelType = TagLib::ID3v2::RelativeVolumeFrame::MasterVolume; |
| | 263 | |
| | 264 | // Fall back on whatever else exists in the frame |
| | 265 | if(NO == channels.contains(TagLib::ID3v2::RelativeVolumeFrame::MasterVolume)) |
| | 266 | channelType = channels.front(); |
| | 267 | |
| | 268 | float volumeAdjustment = relativeVolume->volumeAdjustment(channelType); |
| | 269 | |
| | 270 | if(0 != volumeAdjustment) { |
| | 271 | [metadataDictionary setValue:[NSNumber numberWithFloat:volumeAdjustment] forKey:ReplayGainTrackGainKey]; |
| | 272 | foundReplayGain = YES; |
| | 273 | } |
| | 274 | } |
| | 275 | else if(TagLib::String("replaygain_album_gain", TagLib::String::Latin1) == relativeVolume->identification()) { |
| | 276 | // Attempt to use the master volume if present |
| | 277 | TagLib::List<TagLib::ID3v2::RelativeVolumeFrame::ChannelType> channels = relativeVolume->channels(); |
| | 278 | TagLib::ID3v2::RelativeVolumeFrame::ChannelType channelType = TagLib::ID3v2::RelativeVolumeFrame::MasterVolume; |
| | 279 | |
| | 280 | // Fall back on whatever else exists in the frame |
| | 281 | if(NO == channels.contains(TagLib::ID3v2::RelativeVolumeFrame::MasterVolume)) |
| | 282 | channelType = channels.front(); |
| | 283 | |
| | 284 | float volumeAdjustment = relativeVolume->volumeAdjustment(channelType); |
| | 285 | |
| | 286 | if(0 != volumeAdjustment) { |
| | 287 | [metadataDictionary setValue:[NSNumber numberWithFloat:volumeAdjustment] forKey:ReplayGainAlbumGainKey]; |
| | 288 | foundReplayGain = YES; |
| | 289 | } |
| | 290 | } |
| | 291 | // Fall back to track gain if identification is not specified |
| | 292 | else { |
| | 293 | // Attempt to use the master volume if present |
| | 294 | TagLib::List<TagLib::ID3v2::RelativeVolumeFrame::ChannelType> channels = relativeVolume->channels(); |
| | 295 | TagLib::ID3v2::RelativeVolumeFrame::ChannelType channelType = TagLib::ID3v2::RelativeVolumeFrame::MasterVolume; |
| | 296 | |
| | 297 | // Fall back on whatever else exists in the frame |
| | 298 | if(NO == channels.contains(TagLib::ID3v2::RelativeVolumeFrame::MasterVolume)) |
| | 299 | channelType = channels.front(); |
| | 300 | |
| | 301 | float volumeAdjustment = relativeVolume->volumeAdjustment(channelType); |
| | 302 | |
| | 303 | if(0 != volumeAdjustment) { |
| | 304 | [metadataDictionary setValue:[NSNumber numberWithFloat:volumeAdjustment] forKey:ReplayGainTrackGainKey]; |
| | 305 | foundReplayGain = YES; |
| | 306 | } |
| | 307 | } |
| | 308 | } |