/// <summary> /// Sets time of the specified timed event. /// </summary> /// <param name="timedEvent">Timed event to set time to.</param> /// <param name="time">Time to set to <paramref name="timedEvent"/>.</param> /// <param name="tempoMap">Tempo map that will be used for time conversion.</param> /// <returns>An input <paramref name="timedEvent"/> with new time.</returns> /// <exception cref="ArgumentNullException"> /// <para>One of the following errors occured:</para> /// <list type="bullet"> /// <item> /// <description><paramref name="timedEvent"/> is <c>null</c>.</description> /// </item> /// <item> /// <description><paramref name="time"/> is <c>null</c>.</description> /// </item> /// <item> /// <description><paramref name="tempoMap"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> public static TimedEvent SetTime(this TimedEvent timedEvent, ITimeSpan time, TempoMap tempoMap) { ThrowIfArgument.IsNull(nameof(timedEvent), timedEvent); ThrowIfArgument.IsNull(nameof(time), time); ThrowIfArgument.IsNull(nameof(tempoMap), tempoMap); timedEvent.Time = TimeConverter.ConvertFrom(time, tempoMap); return(timedEvent); }
private bool TryAddTimedEvent(TimedEvent timedEvent) { if (timedEvent == null) { return(false); } _timedObjects.Add(timedEvent); return(true); }
private static bool TryProcessTimedEvent(TimedEvent timedEvent, List <ITimedObject> processedTimedObjects) { if (timedEvent == null) { return(false); } processedTimedObjects.Add(timedEvent); return(true); }
private bool TryAddTimedEvent(TimedEvent timedEvent, ObjectsBuildingSettings settings) { if (timedEvent == null) { return(false); } var handlingBag = _notesBags.FirstOrDefault(b => b.TryAddObject(timedEvent, null, settings)); if (handlingBag != null) { return(true); } return(TryAddObjectToNewNoteBag(timedEvent, settings)); }
private bool TryAddTimedEvent(TimedEvent timedEvent) { if (timedEvent == null) { return(false); } switch (timedEvent.Event.EventType) { case MidiEventType.NoteOn: { if (_timedNoteOnEvent != null) { return(false); } _timedNoteOnEvent = timedEvent; _noteId = ((NoteOnEvent)timedEvent.Event).GetNoteId(); break; } case MidiEventType.NoteOff: { if (_timedNoteOnEvent == null || _timedNoteOffEvent != null) { return(false); } var noteId = ((NoteOffEvent)timedEvent.Event).GetNoteId(); if (!noteId.Equals(_noteId)) { return(false); } _timedNoteOffEvent = timedEvent; break; } default: return(false); } return(true); }
private bool TryAddTimedEvent(TimedEvent timedEvent, RegisteredParametersContext context) { if (timedEvent == null) { return(false); } var controlChangeEvent = timedEvent.Event as ControlChangeEvent; if (controlChangeEvent == null) { return(false); } var controlName = controlChangeEvent.GetControlName(); switch (controlName) { case ControlName.RegisteredParameterNumberMsb: break; case ControlName.RegisteredParameterNumberLsb: break; case ControlName.DataEntryMsb: break; case ControlName.LsbForDataEntry: break; case ControlName.DataIncrement: break; case ControlName.DataDecrement: break; } throw new NotImplementedException(); return(true); }
/// <summary> /// Initializes a new instance of the <see cref="Note"/> with the specified /// Note On and Note Off timed events. /// </summary> /// <param name="timedNoteOnEvent">Wrapped <see cref="NoteOnEvent"/>.</param> /// <param name="timedNoteOffEvent">Wrapped <see cref="NoteOffEvent"/>.</param> internal Note(TimedEvent timedNoteOnEvent, TimedEvent timedNoteOffEvent) { Debug.Assert(timedNoteOnEvent != null); Debug.Assert(timedNoteOnEvent.Event is NoteOnEvent, "Timed event doesn't wrap a Note On event."); Debug.Assert(timedNoteOffEvent != null); Debug.Assert(timedNoteOffEvent.Event is NoteOffEvent, "Timed event doesn't wrap a Note Off event."); // var noteOnEvent = (NoteOnEvent)timedNoteOnEvent.Event; var noteOffEvent = (NoteOffEvent)timedNoteOffEvent.Event; TimedNoteOnEvent = timedNoteOnEvent; TimedNoteOffEvent = timedNoteOffEvent; UnderlyingNote = MusicTheory.Note.Get(noteOnEvent.NoteNumber); Velocity = noteOnEvent.Velocity; OffVelocity = noteOffEvent.Velocity; Channel = noteOnEvent.Channel; }
/// <summary> /// Removes all the <see cref="TimedEvent"/> that match the conditions defined by the specified predicate. /// </summary> /// <param name="eventsCollection"><see cref="EventsCollection"/> to search for events to remove.</param> /// <param name="match">The predicate that defines the conditions of the <see cref="TimedEvent"/> to remove.</param> /// <returns>Count of removed timed events.</returns> /// <exception cref="ArgumentNullException"> /// <para>One of the following errors occured:</para> /// <list type="bullet"> /// <item> /// <description><paramref name="eventsCollection"/> is <c>null</c>.</description> /// </item> /// <item> /// <description><paramref name="match"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> public static int RemoveTimedEvents(this EventsCollection eventsCollection, Predicate <TimedEvent> match) { ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection); ThrowIfArgument.IsNull(nameof(match), match); var eventsCount = eventsCollection.Count; var removedEventsCount = 0; var time = 0L; var latestTime = 0L; var events = eventsCollection._events; for (var i = 0; i < eventsCount; i++) { time += events[i].DeltaTime; var timedEvent = new TimedEvent(events[i], time); if (match(timedEvent)) { removedEventsCount++; } else { events[i].DeltaTime = time - latestTime; events[i - removedEventsCount] = events[i]; latestTime = time; } } if (removedEventsCount > 0) { events.RemoveRange(eventsCount - removedEventsCount, removedEventsCount); } return(removedEventsCount); }
public void CompleteNote(TimedEvent noteOffTimedEvent) { NoteOffTimedEvent = noteOffTimedEvent; IsNoteCompleted = true; }
public NoteEventsDescriptor(TimedEvent noteOnTimedEvent, IEnumerable <TimedEvent> eventsTail) { NoteOnTimedEvent = noteOnTimedEvent; EventsTail = eventsTail; }
private static bool IsTimeSignatureEvent(TimedEvent timedEvent) { return(timedEvent?.Event is TimeSignatureEvent); }
private static bool IsTempoEvent(TimedEvent timedEvent) { return(timedEvent?.Event is SetTempoEvent); }
private static bool IsTempoMapEvent(TimedEvent timedEvent) { return(IsTempoEvent(timedEvent) || IsTimeSignatureEvent(timedEvent)); }
/// <summary> /// Removes all the <see cref="TimedEvent"/> that match the conditions defined by the specified predicate. /// </summary> /// <param name="trackChunks">Collection of <see cref="TrackChunk"/> to search for events to remove.</param> /// <param name="match">The predicate that defines the conditions of the <see cref="TimedEvent"/> to remove.</param> /// <returns>Count of removed timed events.</returns> /// <exception cref="ArgumentNullException"> /// <para>One of the following errors occured:</para> /// <list type="bullet"> /// <item> /// <description><paramref name="trackChunks"/> is <c>null</c>.</description> /// </item> /// <item> /// <description><paramref name="match"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> public static int RemoveTimedEvents(this IEnumerable <TrackChunk> trackChunks, Predicate <TimedEvent> match) { ThrowIfArgument.IsNull(nameof(trackChunks), trackChunks); ThrowIfArgument.IsNull(nameof(match), match); var eventsCollections = trackChunks.Where(c => c != null).Select(c => c.Events).ToArray(); var eventsCount = eventsCollections.Sum(c => c.Count); var eventsCollectionsCount = eventsCollections.Length; if (eventsCollectionsCount == 0) { return(0); } if (eventsCollectionsCount == 1) { return(eventsCollections[0].RemoveTimedEvents(match)); } var eventsCollectionIndices = new int[eventsCollectionsCount]; var eventsCollectionMaxIndices = eventsCollections.Select(c => c.Count - 1).ToArray(); var eventsCollectionTimes = new long[eventsCollectionsCount]; var eventsCollectionLatestTimes = new long[eventsCollectionsCount]; var removedEventsCounts = new int[eventsCollectionsCount]; for (var i = 0; i < eventsCount; i++) { var eventsCollectionIndex = 0; var minTime = long.MaxValue; for (var j = 0; j < eventsCollectionsCount; j++) { var index = eventsCollectionIndices[j]; if (index > eventsCollectionMaxIndices[j]) { continue; } var eventTime = eventsCollections[j][index].DeltaTime + eventsCollectionTimes[j]; if (eventTime < minTime) { minTime = eventTime; eventsCollectionIndex = j; } } var midiEvent = eventsCollections[eventsCollectionIndex][eventsCollectionIndices[eventsCollectionIndex]]; var timedEvent = new TimedEvent(midiEvent, minTime); if (match(timedEvent)) { removedEventsCounts[eventsCollectionIndex]++; } else { midiEvent.DeltaTime = minTime - eventsCollectionLatestTimes[eventsCollectionIndex]; eventsCollections[eventsCollectionIndex][eventsCollectionIndices[eventsCollectionIndex] - removedEventsCounts[eventsCollectionIndex]] = midiEvent; eventsCollectionLatestTimes[eventsCollectionIndex] = minTime; } eventsCollectionTimes[eventsCollectionIndex] = minTime; eventsCollectionIndices[eventsCollectionIndex]++; } for (var i = 0; i < eventsCollectionsCount; i++) { var removedEventsCount = removedEventsCounts[i]; if (removedEventsCount > 0) { eventsCollections[i]._events.RemoveRange(eventsCollections[i].Count - removedEventsCount, removedEventsCount); } } return(removedEventsCounts.Sum()); }