private static void TestGetNotesAndRests(
            IEnumerable <Note> inputNotes,
            RestSeparationPolicy restSeparationPolicy,
            IEnumerable <ILengthedObject> expectedObjects)
        {
            var actualObjects = inputNotes.GetNotesAndRests(restSeparationPolicy);

            MidiAsserts.AreEqual(expectedObjects, actualObjects, true, 0, "Objects are invalid");
        }
        private static void TestGetNotesAndRests(
            IEnumerable <Note> inputNotes,
            RestSeparationPolicy restSeparationPolicy,
            IEnumerable <ILengthedObject> expectedObjects)
        {
            var actualObjects = inputNotes.GetNotesAndRests(restSeparationPolicy);

            CollectionAssert.AreEqual(
                expectedObjects,
                actualObjects,
                new LengthedObjectComparer());
        }
 private void GetObjects_Rests(
     RestSeparationPolicy restSeparationPolicy,
     IEnumerable <ITimedObject> inputObjects,
     IEnumerable <ITimedObject> outputObjects)
 {
     GetObjects(
         inputObjects,
         outputObjects,
         ObjectType.Rest,
         new ObjectDetectionSettings
     {
         RestDetectionSettings = new RestDetectionSettings
         {
             RestSeparationPolicy = restSeparationPolicy
         }
     });
 }
 private void GetObjects_NotesAndRests(
     RestSeparationPolicy restSeparationPolicy,
     IEnumerable <ITimedObject> inputObjects,
     IEnumerable <ITimedObject> outputObjects,
     NoteDetectionSettings noteDetectionSettings = null)
 {
     GetObjects(
         inputObjects,
         outputObjects,
         ObjectType.Note | ObjectType.Rest,
         new ObjectDetectionSettings
     {
         RestDetectionSettings = new RestDetectionSettings
         {
             RestSeparationPolicy = restSeparationPolicy
         },
         NoteDetectionSettings = noteDetectionSettings ?? new NoteDetectionSettings()
     });
 }
        /// <summary>
        /// Iterates through the specified collection of <see cref="Note"/> returning instances of <see cref="Note"/>
        /// and <see cref="Rest"/> where rests calculated using the specified policy.
        /// </summary>
        /// <param name="notes">Collection of <see cref="Note"/> to iterate over.</param>
        /// <param name="restSeparationPolicy">Policy which determines when rests should be returned.</param>
        /// <returns>Collection of <see cref="ITimedObject"/> where an element either <see cref="Note"/>
        /// or <see cref="Rest"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="notes"/> is null.</exception>
        /// <exception cref="InvalidEnumArgumentException"><paramref name="restSeparationPolicy"/> specified an
        /// invalid value.</exception>
        public static IEnumerable <ILengthedObject> GetNotesAndRests(
            this IEnumerable <Note> notes,
            RestSeparationPolicy restSeparationPolicy)
        {
            ThrowIfArgument.IsNull(nameof(notes), notes);
            ThrowIfArgument.IsInvalidEnumValue(nameof(restSeparationPolicy), restSeparationPolicy);

            switch (restSeparationPolicy)
            {
            case RestSeparationPolicy.NoSeparation:
                return(GetNotesAndRests(notes,
                                        n => NoSeparationNoteDescriptor,
                                        false,
                                        false));

            case RestSeparationPolicy.SeparateByChannel:
                return(GetNotesAndRests(notes,
                                        n => n.Channel,
                                        true,
                                        false));

            case RestSeparationPolicy.SeparateByNoteNumber:
                return(GetNotesAndRests(notes,
                                        n => n.NoteNumber,
                                        false,
                                        true));

            case RestSeparationPolicy.SeparateByChannelAndNoteNumber:
                return(GetNotesAndRests(notes,
                                        n => n.GetNoteId(),
                                        true,
                                        true));
            }

            throw new NotSupportedException($"Rest separation policy {restSeparationPolicy} is not supported.");
        }
예제 #6
0
        public static IEnumerable <ILengthedObject> GetNotesAndRests(this IEnumerable <TrackChunk> trackChunks, RestSeparationPolicy restSeparationPolicy)
        {
            ThrowIfArgument.IsNull(nameof(trackChunks), trackChunks);
            ThrowIfArgument.IsInvalidEnumValue(nameof(restSeparationPolicy), restSeparationPolicy);

            return(trackChunks.GetNotes().GetNotesAndRests(restSeparationPolicy));
        }
예제 #7
0
        public static IEnumerable <ILengthedObject> GetNotesAndRests(this IEnumerable <Note> notes, RestSeparationPolicy restSeparationPolicy)
        {
            ThrowIfArgument.IsNull(nameof(notes), notes);
            ThrowIfArgument.IsInvalidEnumValue(nameof(restSeparationPolicy), restSeparationPolicy);

            return(notes
                   .GetObjects(ObjectType.Note | ObjectType.Rest, new ObjectDetectionSettings
            {
                RestDetectionSettings = new RestDetectionSettings
                {
                    RestSeparationPolicy = restSeparationPolicy
                }
            })
                   .OfType <ILengthedObject>());
        }
예제 #8
0
        public static IEnumerable <ILengthedObject> GetNotesAndRests(this MidiFile midiFile, RestSeparationPolicy restSeparationPolicy)
        {
            ThrowIfArgument.IsNull(nameof(midiFile), midiFile);
            ThrowIfArgument.IsInvalidEnumValue(nameof(restSeparationPolicy), restSeparationPolicy);

            return(midiFile.GetNotes().GetNotesAndRests(restSeparationPolicy));
        }
예제 #9
0
        public static IEnumerable <ILengthedObject> GetNotesAndRests(this TrackChunk trackChunk, RestSeparationPolicy restSeparationPolicy)
        {
            ThrowIfArgument.IsNull(nameof(trackChunk), trackChunk);

            return(trackChunk.GetNotes().GetNotesAndRests(restSeparationPolicy));
        }