Example #1
0
        private void FrameAdd(object sender, ListItemAddEventArgs<Id3v2Frame> e)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            if (e.Item == null)
                throw new NullReferenceException("e.Item may not be null");

            string identifier = Id3v2Frame.GetIdentifier<Id3v2MusicCdIdentifierFrame>(e.Item.Version);
            if ((e.Item is Id3v2MusicCdIdentifierFrame || String.Equals(e.Item.Identifier, identifier, StringComparison.OrdinalIgnoreCase))
                && TrackNumber == null)
            {
                // The 'Music CD Identifier' frame requires a present and valid TRCK frame.
                throw new InvalidOperationException(
                    "TrackNumber frame is required to be present and valid before adding a MusicCdIdentifier frame, even if the CD's only got one track.");
            }

            if (Version >= Id3v2Version.Id3v240)
            {
                identifier = Id3v2Frame.GetIdentifier<Id3v2AudioSeekPointIndexFrame>(e.Item.Version);
                if ((e.Item is Id3v2AudioSeekPointIndexFrame || String.Equals(e.Item.Identifier, identifier, StringComparison.OrdinalIgnoreCase))
                    && Length == null)
                {
                    // The presence of an 'Audio seek point index' frame requires the existence of a TLEN frame, indicating the duration of the file in milliseconds.
                    throw new InvalidOperationException("Length frame is required to be present before adding an audio seek point index frame.");
                }
            }
        }
        private static void ChannelInformationAdd(object sender, ListItemAddEventArgs<Id3v2ChannelInformation> e)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            if (e.Item == null)
                throw new NullReferenceException("e.Item may not be null");

            if (!IsValidChannelType(e.Item.ChannelType))
                throw new InvalidDataException("value contains one or more invalid channel types.");
        }
        private void KeyEventAdd(object sender, ListItemAddEventArgs<Id3v2KeyEvent> e)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            if (e.Item == null)
                throw new NullReferenceException("e.Item may not be null");

            if (!IsValidKeyEventType(e.Item.EventType))
                throw new InvalidDataException(String.Format("value contains one or more key event types not supported in version {0}.", Version));

            for (int i = 0; i < _keyEvents.Count; i++)
            {
                Id3v2KeyEvent keyEvent = _keyEvents[i];
                if (keyEvent.EventType >= e.Item.EventType)
                {
                    e.Index = i;
                    break;
                }
            }
        }
        // Manually insert the AdjustmentPoint here so we can keep the list always sorted by Frequency.
        private void AdjustmentPointAdd(object sender, ListItemAddEventArgs<Id3v2AdjustmentPoint> e)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            if (e.Item == null)
                throw new NullReferenceException("e.Item may not be null");

            for (int i = 0; i < _adjustmentPoints.Count; i++)
            {
                Id3v2AdjustmentPoint adjustmentPoint = _adjustmentPoints[i];
                if (adjustmentPoint.Frequency >= e.Item.Frequency)
                {
                    e.Index = i;
                    break;
                }
            }
        }
        private void InvolvedPeopleAdd(object sender, ListItemAddEventArgs<Id3v2InvolvedPeople> e)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            if (e.Item == null)
                throw new NullReferenceException("e.Item may not be null");

            if (!String.IsNullOrEmpty(e.Item.Involvee) && !IsValidTextString(e.Item.Involvee, TextEncoding, false))
            {
                throw new InvalidDataException(
                    "value contains one or more Involvee entries with one or more invalid characters for the current frame encoding type.");
            }

            if (!String.IsNullOrEmpty(e.Item.Involvement) && !IsValidTextString(e.Item.Involvement, TextEncoding, false))
            {
                throw new InvalidDataException(
                    "value contains one or more Involvement entries with one or more invalid characters for the current frame encoding type.");
            }
        }
        private void LyricSyncAdd(object sender, ListItemAddEventArgs<Id3v2LyricSync> e)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            if (e.Item == null)
                throw new NullReferenceException("e.Item may not be null");

            if (e.Item.Syllable == null)
                throw new NullReferenceException("e.Syllable may not be null");

            if (!IsValidTextString(e.Item.Syllable, TextEncoding, false))
            {
                throw new InvalidDataException(
                    "value contains one or more Syllable entries with one or more invalid characters for the current frame encoding type.");
            }

            for (int i = 0; i < _lyricSyncs.Count; i++)
            {
                Id3v2LyricSync lyricSync = _lyricSyncs[i];
                if (lyricSync.TimeStamp >= e.Item.TimeStamp)
                {
                    e.Index = i;
                    break;
                }
            }
        }
        private void EqualisationBandAdd(object sender, ListItemAddEventArgs<Id3v2EqualisationBand> e)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            if (e.Item == null)
                throw new NullReferenceException("e.Item may not be null");

            for (int i = 0; i < _equalisationBands.Count; i++)
            {
                Id3v2EqualisationBand equalisationBand = _equalisationBands[i];
                if (equalisationBand.Frequency >= e.Item.Frequency)
                {
                    e.Index = i;
                    break;
                }
            }
        }
Example #8
0
        private void ValueAdd(object sender, ListItemAddEventArgs<string> e)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            if (e.Item == null)
                throw new NullReferenceException("e.Item may not be null");

            if (!IsValidTextString(e.Item, TextEncoding, false))
                throw new InvalidDataException("value contains one or more invalid characters for the current frame encoding type.");
        }
Example #9
0
        private static void ItemAdd(object sender, ListItemAddEventArgs<string> e)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            if (e.Item == null)
                throw new NullReferenceException("e.Item may not be null");

            if (!Uri.IsWellFormedUriString(e.Item, UriKind.RelativeOrAbsolute))
                throw new InvalidDataException("One or more URI values are invalid.");
        }
        private void TempoCodeAdd(object sender, ListItemAddEventArgs<Id3v2TempoCode> e)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            if (e.Item == null)
                throw new NullReferenceException("e.Item may not be null");

            for (int i = 0; i < _tempoCodes.Count; i++)
            {
                Id3v2TempoCode tempoCode = _tempoCodes[i];
                if (tempoCode.TimeStamp >= e.Item.TimeStamp)
                {
                    e.Index = i;
                    break;
                }
            }
        }
        ////------------------------------------------------------------------------------------------------------------------------------
        private void SeekPointAdd(object sender, ListItemAddEventArgs<FlacSeekPoint> e)
        {
            if (e == null)
                throw new ArgumentNullException("e");

            if (e.Item == null)
                throw new NullReferenceException("e.Item may not be null");

            // Seek points within a table must be unique by sample number, with the exception of placeholder points.
            for (int i = 0; i < _seekPoints.Count; i++)
            {
                FlacSeekPoint seekPoint = _seekPoints[i];

                // Seek points within a table must be sorted in ascending order by sample number.
                if (seekPoint.SampleNumber >= e.Item.SampleNumber)
                {
                    e.Index = i;
                    break;
                }
            }
        }