Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ChordsManager"/> with the specified events
        /// collection, notes tolerance and comparison delegate for events that have same time.
        /// </summary>
        /// <param name="eventsCollection"><see cref="EventsCollection"/> that holds chord events to manage.</param>
        /// <param name="notesTolerance">Notes tolerance that defines maximum distance of notes from the
        /// start of the first note of a chord. Notes within this tolerance will be considered as a chord.</param>
        /// <param name="sameTimeEventsComparison">Delegate to compare events with the same absolute time.</param>
        /// <exception cref="ArgumentNullException"><paramref name="eventsCollection"/> is null.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="notesTolerance"/> is negative.</exception>
        public ChordsManager(EventsCollection eventsCollection, long notesTolerance = 0, Comparison <MidiEvent> sameTimeEventsComparison = null)
        {
            ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection);
            ThrowIfNotesTolerance.IsNegative(nameof(notesTolerance), notesTolerance);

            _notesManager = eventsCollection.ManageNotes(sameTimeEventsComparison);

            Chords = new ChordsCollection(CreateChords(_notesManager.Notes, notesTolerance));
            Chords.CollectionChanged += OnChordsCollectionChanged;
        }
Пример #2
0
        private void OnChordsCollectionChanged(ChordsCollection collection, ChordsCollectionChangedEventArgs args)
        {
            var addedChords = args.AddedChords;

            if (addedChords != null)
            {
                foreach (var chord in addedChords)
                {
                    AddNotes(chord.Notes);
                    SubscribeToChordEvents(chord);
                }
            }

            var removedChords = args.RemovedChords;

            if (removedChords != null)
            {
                foreach (var chord in removedChords)
                {
                    RemoveNotes(chord.Notes);
                    UnsubscribeFromChordEvents(chord);
                }
            }
        }