Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Chord"/> with the specified
        /// collection of notes.
        /// </summary>
        /// <param name="notes">Notes to combine into a chord.</param>
        /// <exception cref="ArgumentNullException"><paramref name="notes"/> is null.</exception>
        public Chord(IEnumerable <Note> notes)
        {
            ThrowIfArgument.IsNull(nameof(notes), notes);

            Notes = new NotesCollection(notes);
            Notes.CollectionChanged += OnNotesCollectionChanged;
        }
Пример #2
0
        private void OnNotesCollectionChanged(NotesCollection collection, NotesCollectionChangedEventArgs args)
        {
            _channel     = null;
            _velocity    = null;
            _offVelocity = null;

            NotesCollectionChanged?.Invoke(collection, args);
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NotesManager"/> with the specified events
        /// collection and comparison delegate for events that have same time.
        /// </summary>
        /// <param name="eventsCollection"><see cref="EventsCollection"/> that holds note events to manage.</param>
        /// <param name="settings">Settings accoridng to which notes should be detected and built.</param>
        /// <param name="sameTimeEventsComparison">Delegate to compare events with the same absolute time.</param>
        /// <remarks>
        /// If the <paramref name="sameTimeEventsComparison"/> is not specified events with the same time
        /// will be placed into the underlying events collection in order of adding them through the manager.
        /// If you want to specify custom order of such events you need to specify appropriate comparison delegate.
        /// </remarks>
        /// <exception cref="ArgumentNullException"><paramref name="eventsCollection"/> is <c>null</c>.</exception>
        public NotesManager(EventsCollection eventsCollection, NoteDetectionSettings settings = null, Comparison <MidiEvent> sameTimeEventsComparison = null)
        {
            ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection);

            _timedEventsManager = eventsCollection.ManageTimedEvents(sameTimeEventsComparison);

            Notes = new NotesCollection(_timedEventsManager.Events.GetNotesAndTimedEventsLazy(settings).OfType <Note>());
            Notes.CollectionChanged += OnNotesCollectionChanged;
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NotesManager"/> with the specified events
        /// collection and comparison delegate for events that have same time.
        /// </summary>
        /// <param name="eventsCollection"><see cref="EventsCollection"/> that holds note events to manage.</param>
        /// <param name="sameTimeEventsComparison">Delegate to compare events with the same absolute time.</param>
        /// <remarks>
        /// If the <paramref name="sameTimeEventsComparison"/> is not specified events with the same time
        /// will be placed into the underlying events collection in order of adding them through the manager.
        /// If you want to specify custom order of such events you need to specify appropriate comparison delegate.
        /// </remarks>
        /// <exception cref="ArgumentNullException"><paramref name="eventsCollection"/> is <c>null</c>.</exception>
        public NotesManager(EventsCollection eventsCollection, Comparison <MidiEvent> sameTimeEventsComparison = null)
        {
            ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection);

            _timedEventsManager = eventsCollection.ManageTimedEvents(sameTimeEventsComparison);

            Notes = new NotesCollection(CreateNotes(_timedEventsManager.Events));
            Notes.CollectionChanged += OnNotesCollectionChanged;
        }
Пример #5
0
        private void OnChordNotesCollectionChanged(NotesCollection collection, NotesCollectionChangedEventArgs args)
        {
            var addedNotes = args.AddedNotes;

            if (addedNotes != null)
            {
                AddNotes(addedNotes);
            }

            var removedNotes = args.RemovedNotes;

            if (removedNotes != null)
            {
                RemoveNotes(removedNotes);
            }
        }
Пример #6
0
        private void OnNotesCollectionChanged(NotesCollection collection, NotesCollectionChangedEventArgs args)
        {
            var addedNotes = args.AddedNotes;

            if (addedNotes != null)
            {
                _timedEventsManager.Events.Add(GetNotesTimedEvents(addedNotes));
            }

            var removedNotes = args.RemovedNotes;

            if (removedNotes != null)
            {
                _timedEventsManager.Events.Remove(GetNotesTimedEvents(removedNotes));
            }
        }
Пример #7
0
 private void OnNotesCollectionChanged(NotesCollection collection, NotesCollectionChangedEventArgs args)
 {
     NotesCollectionChanged?.Invoke(collection, args);
 }