public static void AddTimedEvents(this EventsCollection eventsCollection, IEnumerable <TimedEvent> events) { ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection); ThrowIfArgument.IsNull(nameof(events), events); using (var timedEventsManager = eventsCollection.ManageTimedEvents()) { timedEventsManager.Events.Add(events.Where(e => e.Event is ChannelEvent || e.Event is MetaEvent || e.Event is SysExEvent)); } }
/// <summary> /// Adds collection of chords to the specified <see cref="EventsCollection"/>. /// </summary> /// <param name="eventsCollection"><see cref="EventsCollection"/> to add chords to.</param> /// <param name="chords">Chords to add to the <paramref name="eventsCollection"/>.</param> /// <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="chords"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> public static void AddChords(this EventsCollection eventsCollection, IEnumerable <Chord> chords) { ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection); ThrowIfArgument.IsNull(nameof(chords), chords); using (var chordsManager = eventsCollection.ManageChords()) { chordsManager.Chords.Add(chords); } }
/// <summary> /// Removes all the <see cref="Chord"/> that match the conditions defined by the specified predicate. /// </summary> /// <param name="eventsCollection"><see cref="EventsCollection"/> to search for chords to remove.</param> /// <param name="match">The predicate that defines the conditions of the <see cref="Chord"/> to remove.</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> /// <exception cref="ArgumentNullException"><paramref name="eventsCollection"/> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="notesTolerance"/> is negative.</exception> public static void RemoveChords(this EventsCollection eventsCollection, Predicate <Chord> match = null, long notesTolerance = 0) { ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection); ThrowIfNotesTolerance.IsNegative(nameof(notesTolerance), notesTolerance); using (var chordsManager = eventsCollection.ManageChords(notesTolerance)) { chordsManager.Chords.RemoveAll(match ?? (c => true)); } }
/// <summary> /// Adds collection of notes to the specified <see cref="EventsCollection"/>. /// </summary> /// <param name="eventsCollection"><see cref="EventsCollection"/> to add notes to.</param> /// <param name="notes">Notes to add to the <paramref name="eventsCollection"/>.</param> /// <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="notes"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> public static void AddNotes(this EventsCollection eventsCollection, IEnumerable <Note> notes) { ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection); ThrowIfArgument.IsNull(nameof(notes), notes); using (var notesManager = eventsCollection.ManageNotes()) { notesManager.Notes.Add(notes); } }
/// <summary> /// Adds collection of timed events to the specified <see cref="EventsCollection"/>. /// </summary> /// <param name="eventsCollection"><see cref="EventsCollection"/> to add timed events to.</param> /// <param name="events">Timed events to add to the <paramref name="eventsCollection"/>.</param> /// <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="events"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> public static void AddTimedEvents(this EventsCollection eventsCollection, IEnumerable <TimedEvent> events) { ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection); ThrowIfArgument.IsNull(nameof(events), events); using (var timedEventsManager = eventsCollection.ManageTimedEvents()) { timedEventsManager.Events.Add(events); } }
public GroupsViewModel(string key, ulong parameter) : base(key, parameter) { _groups = new GroupsCollection(parameter); _events = new EventsCollection(parameter); _manage = new GroupsManageCollection(parameter); Refresh = new RelayCommand(() => Groups.Refresh()); RefreshEvents = new RelayCommand(() => Events.Refresh()); RefreshGroupsManage = new RelayCommand(() => GroupsManage.Refresh()); }
/// <summary> /// Gets notes contained in the specified collection of <see cref="MidiEvent"/>. /// </summary> /// <param name="events">Collection of<see cref="MidiFile"/> to search for notes.</param> /// <returns>Collection of notes contained in <paramref name="events"/> ordered by time.</returns> /// <exception cref="ArgumentNullException"><paramref name="events"/> is <c>null</c>.</exception> public static IEnumerable <Note> GetNotes(this IEnumerable <MidiEvent> events) { ThrowIfArgument.IsNull(nameof(events), events); var eventsCollection = new EventsCollection(); eventsCollection.AddRange(events); return(eventsCollection.ManageNotes().Notes.ToList()); }
/// <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 <c>null</c>.</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; }
private void Details(object sender, ItemClickEventArgs e) { if (!(EventsCollection.ContainerFromItem(e.ClickedItem) is ListViewItem container)) { return; } if (container.Content is Event selectedEvent) { Frame.Navigate(typeof(EventDetails), selectedEvent); } }
/// <summary> /// Extracts objects of the specified types from a <see cref="EventsCollection"/>. /// </summary> /// <param name="eventsCollection"><see cref="EventsCollection"/> to extract objects from.</param> /// <param name="objectType">Combination of desired objects types.</param> /// <param name="settings">Settings according to which objects should be detected and built.</param> /// <returns>Collection of objects of the specified types extracted from <paramref name="eventsCollection"/>. /// Objects are ordered by time.</returns> /// <exception cref="ArgumentNullException"><paramref name="eventsCollection"/> is <c>null</c>.</exception> public static ICollection <ITimedObject> GetObjects( this EventsCollection eventsCollection, ObjectType objectType, ObjectDetectionSettings settings = null) { ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection); return(eventsCollection .GetTimedEventsLazy() .GetObjectsFromSortedTimedObjects(eventsCollection.Count / 2, objectType, settings)); }
/// <summary> /// Gets chords contained in the specified collection of <see cref="MidiEvent"/>. /// </summary> /// <param name="events">Collection of<see cref="MidiFile"/> to search for chords.</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> /// <returns>Collection of chords contained in <paramref name="events"/> ordered by time.</returns> /// <exception cref="ArgumentNullException"><paramref name="events"/> is <c>null</c>.</exception> public static IEnumerable <Chord> GetChords(this IEnumerable <MidiEvent> events, long notesTolerance = 0) { ThrowIfArgument.IsNull(nameof(events), events); ThrowIfNotesTolerance.IsNegative(nameof(notesTolerance), notesTolerance); var eventsCollection = new EventsCollection(); eventsCollection.AddRange(events); return(eventsCollection.ManageChords(notesTolerance).Chords.ToList()); }
private static IEnumerable <TimedEvent> CreateTimedEvents(EventsCollection events) { ThrowIfArgument.IsNull(nameof(events), events); var time = 0L; foreach (var midiEvent in events) { time += midiEvent.DeltaTime; yield return(new TimedEvent(midiEvent.Clone(), time)); } }
public static void AreEqual(EventsCollection eventsCollection1, EventsCollection eventsCollection2, bool compareDeltaTimes, string message = null) { var areEqual = EventsCollectionEquality.Equals( eventsCollection1, eventsCollection2, new MidiEventEqualityCheckSettings { CompareDeltaTimes = compareDeltaTimes }, out var eventsComparingMessage); Assert.IsTrue(areEqual, $"{message} {eventsComparingMessage}"); }
private void RemoveTimedEvents_EventsCollection_WithoutPredicate( ContainerType containerType, ICollection <MidiEvent> midiEvents) { var eventsCollection = new EventsCollection(); eventsCollection.AddRange(midiEvents); switch (containerType) { case ContainerType.EventsCollection: { Assert.AreEqual( midiEvents.Count, eventsCollection.RemoveTimedEvents(), "Invalid count of removed timed events."); var expectedEventsCollection = new EventsCollection(); MidiAsserts.AreEqual(expectedEventsCollection, eventsCollection, true, "Events are invalid."); Assert.IsTrue( eventsCollection.All(e => midiEvents.Any(ee => object.ReferenceEquals(e, ee))), "There are new events references."); } break; case ContainerType.TrackChunk: { var trackChunk = new TrackChunk(eventsCollection); Assert.AreEqual( midiEvents.Count, trackChunk.RemoveTimedEvents(), "Invalid count of removed timed events."); var expectedTrackChunk = new TrackChunk(); MidiAsserts.AreEqual(expectedTrackChunk, trackChunk, true, "Events are invalid."); Assert.IsTrue( trackChunk.Events.All(e => midiEvents.Any(ee => object.ReferenceEquals(e, ee))), "There are new events references."); } break; case ContainerType.TrackChunks: case ContainerType.File: { RemoveTimedEvents_TrackChunks_WithoutPredicate( containerType == ContainerType.File, new[] { midiEvents }); } break; } }
/// <summary> /// Performs the specified action on each <see cref="Note"/> contained in the <see cref="EventsCollection"/>. /// </summary> /// <param name="eventsCollection"><see cref="EventsCollection"/> to search for notes to process.</param> /// <param name="action">The action to perform on each <see cref="Note"/> contained in the /// <paramref name="eventsCollection"/>.</param> /// <param name="match">The predicate that defines the conditions of the <see cref="Note"/> to process.</param> /// <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="action"/> is <c>null</c>.</description> /// </item> /// </list> /// </exception> public static void ProcessNotes(this EventsCollection eventsCollection, Action <Note> action, Predicate <Note> match = null) { ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection); ThrowIfArgument.IsNull(nameof(action), action); using (var notesManager = eventsCollection.ManageNotes()) { foreach (var note in notesManager.Notes.Where(n => match?.Invoke(n) != false)) { action(note); } } }
/// <summary> /// Invoked when application execution is being suspended. Application state is saved /// without knowing whether the application will be terminated or resumed with the contents /// of memory still intact. /// </summary> /// <param name="sender">The source of the suspend request.</param> /// <param name="e">Details about the suspend request.</param> private void OnSuspending(object sender, SuspendingEventArgs e) { Task.Run(async() => { await SensorCollection?.BeginShutdown(); await EventsCollection?.BeginShutdown(); }).Wait(); var deferral = e.SuspendingOperation.GetDeferral(); //TODO: Save application state and stop any background activity deferral.Complete(); }
/// <summary> /// Gets timed events contained in the specified <see cref="EventsCollection"/>. /// </summary> /// <param name="eventsCollection"><see cref="EventsCollection"/> to search for events.</param> /// <returns>Collection of timed events contained in <paramref name="eventsCollection"/> ordered by time.</returns> /// <exception cref="ArgumentNullException"><paramref name="eventsCollection"/> is <c>null</c>.</exception> public static ICollection <TimedEvent> GetTimedEvents(this EventsCollection eventsCollection) { ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection); var result = new List <TimedEvent>(eventsCollection.Count); foreach (var timedEvent in eventsCollection.GetTimedEventsLazy()) { result.Add(timedEvent); } return(result); }
/// <summary> /// Performs the specified action on each <see cref="TimedEvent"/> contained in the <see cref="EventsCollection"/>. /// </summary> /// <param name="eventsCollection"><see cref="EventsCollection"/> to search for events to process.</param> /// <param name="action">The action to perform on each <see cref="TimedEvent"/> contained in the /// <paramref name="eventsCollection"/>.</param> /// <param name="match">The predicate that defines the conditions of the <see cref="TimedEvent"/> to process.</param> /// <exception cref="ArgumentNullException"><paramref name="eventsCollection"/> is null. -or- /// <paramref name="action"/> is null.</exception> public static void ProcessTimedEvents(this EventsCollection eventsCollection, Action <TimedEvent> action, Predicate <TimedEvent> match = null) { ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection); ThrowIfArgument.IsNull(nameof(action), action); using (var timedEventsManager = eventsCollection.ManageTimedEvents()) { foreach (var timedEvent in timedEventsManager.Events.Where(e => match?.Invoke(e) != false)) { action(timedEvent); } } }
internal static void SortAndUpdateEvents(this EventsCollection eventsCollection, IEnumerable <TimedEvent> timedEvents) { var time = 0L; var i = 0; foreach (var e in timedEvents.OrderBy(e => e.Time)) { var midiEvent = e.Event; midiEvent.DeltaTime = e.Time - time; eventsCollection[i++] = midiEvent; time = e.Time; } }
/// <summary> /// Performs the specified action on each <see cref="Chord"/> contained in the <see cref="EventsCollection"/>. /// </summary> /// <param name="eventsCollection"><see cref="EventsCollection"/> to search for chords to process.</param> /// <param name="action">The action to perform on each <see cref="Chord"/> contained in the /// <paramref name="eventsCollection"/>.</param> /// <param name="match">The predicate that defines the conditions of the <see cref="Chord"/> to process.</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> /// <exception cref="ArgumentNullException"><paramref name="eventsCollection"/> is null. -or- /// <paramref name="action"/> is null.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="notesTolerance"/> is negative.</exception> public static void ProcessChords(this EventsCollection eventsCollection, Action <Chord> action, Predicate <Chord> match = null, long notesTolerance = 0) { ThrowIfArgument.IsNull(nameof(eventsCollection), eventsCollection); ThrowIfArgument.IsNull(nameof(action), action); ThrowIfNotesTolerance.IsNegative(nameof(notesTolerance), notesTolerance); using (var chordsManager = eventsCollection.ManageChords(notesTolerance)) { foreach (var chord in chordsManager.Chords.Where(c => match?.Invoke(c) != false)) { action(chord); } } }
private void GetNotes_DetectionSettings_EventsCollection( ContainerType containerType, NoteDetectionSettings settings, ICollection <MidiEvent> midiEvents, ICollection <Note> expectedNotes) { switch (containerType) { case ContainerType.EventsCollection: { var eventsCollection = new EventsCollection(); eventsCollection.AddRange(midiEvents); var notes = eventsCollection.GetNotes(settings); MidiAsserts.AreEqual(expectedNotes, notes, "Notes are invalid."); var timedObjects = eventsCollection.GetObjects(ObjectType.Note, new ObjectDetectionSettings { NoteDetectionSettings = settings }); MidiAsserts.AreEqual(expectedNotes, timedObjects, "Notes are invalid from GetObjects."); } break; case ContainerType.TrackChunk: { var trackChunk = new TrackChunk(midiEvents); var notes = trackChunk.GetNotes(settings); MidiAsserts.AreEqual(expectedNotes, notes, "Notes are invalid."); var timedObjects = trackChunk.GetObjects(ObjectType.Note, new ObjectDetectionSettings { NoteDetectionSettings = settings }); MidiAsserts.AreEqual(expectedNotes, timedObjects, "Notes are invalid from GetObjects."); } break; case ContainerType.TrackChunks: case ContainerType.File: { GetNotes_DetectionSettings_TrackChunks( containerType == ContainerType.File, settings, new[] { midiEvents }, expectedNotes); } break; } }
// Token: 0x06002A5E RID: 10846 RVA: 0x00137824 File Offset: 0x00135A24 private static string smethod_0(EventsCollection eventsCollection_0) { for (int i = 0; i < eventsCollection_0.Count; i++) { if (eventsCollection_0[i].GetType() == typeof(SequenceTrackNameEvent)) { string text = ((SequenceTrackNameEvent)eventsCollection_0[i]).Text.ToLower(); if (text.Contains("part") || text == "t1 gems" || text == "events" || text == "beat") { return(text); } } } return(""); }
// Token: 0x06002A60 RID: 10848 RVA: 0x00137BB0 File Offset: 0x00135DB0 private static void smethod_2(EventsCollection eventsCollection_0, Song gclass27_0) { if (!GClass30.bool_0) { gclass27_0.list_0 = new List <float>(); for (int i = 0; i < eventsCollection_0.Count; i++) { NoteOnEvent noteOnEvent = eventsCollection_0[i] as NoteOnEvent; if (noteOnEvent != null && noteOnEvent.OffEvent != null && (noteOnEvent.NoteNumber == 12 || noteOnEvent.NoteNumber == 13)) { gclass27_0.list_0.Add(gclass27_0.method_52((uint)noteOnEvent.AbsoluteTime)); } } } }
private static void AddTimedEventsToEventsCollection(EventsCollection eventsCollection, IEnumerable <ITimedObject> timedObjects) { var time = 0L; foreach (TimedEvent timedEvent in timedObjects) { var midiEvent = timedEvent.Event; if (midiEvent is ChannelEvent || midiEvent is MetaEvent || midiEvent is SysExEvent) { midiEvent.DeltaTime = timedEvent.Time - time; eventsCollection._events.Add(midiEvent); time = timedEvent.Time; } } }
public static string GenerateTrackData(TrackChunk track) { if (track == null) { return(null); } StringBuilder output = new StringBuilder(); EventsCollection trackEvents = track.Events; foreach (MidiEvent currentEvent in trackEvents) { output.Append($"{currentEvent.ToString()}\n"); } return(output.ToString()); }
private void GetChords_EventsCollection( ContainerType containerType, ICollection <MidiEvent> midiEvents, ICollection <Chord> expectedChords) { switch (containerType) { case ContainerType.EventsCollection: { var eventsCollection = new EventsCollection(); eventsCollection.AddRange(midiEvents); var chords = eventsCollection.GetChords(); MidiAsserts.AreEqual(expectedChords, chords, "Chords are invalid."); var timedObjects = eventsCollection.GetObjects(ObjectType.Chord); MidiAsserts.AreEqual(expectedChords, timedObjects, "Chords are invalid from GetObjects."); } break; case ContainerType.TrackChunk: { var trackChunk = new TrackChunk(midiEvents); var chords = trackChunk.GetChords(); MidiAsserts.AreEqual(expectedChords, chords, "Chords are invalid."); var timedObjects = trackChunk.GetObjects(ObjectType.Chord); MidiAsserts.AreEqual(expectedChords, timedObjects, "Chords are invalid from GetObjects."); } break; case ContainerType.TrackChunks: case ContainerType.File: { GetChords_TrackChunks( containerType == ContainerType.File, new[] { midiEvents }, expectedChords); } break; } }
private void CreateCommands() { RefreshEventsCommand = new Command(() => { try { IsBusy = true; EventsCollection.Clear(); cts.Cancel(); cts.Dispose(); cts = new CancellationTokenSource(); LoadEvents(_type, true); } catch (Exception) {} finally { IsBusy = false; } }); }
async void SyncSchedules() { if (!IsBusy) { Exception Error = null; BarberSchedulesList.Clear(); EventsCollection.Clear(); try { IsBusy = true; var Repository = new Repository(); var Items = await Repository.GetSchedule(); foreach (var Schedule in Items) { BarberSchedulesList.Add(Schedule); eventAppointment.From = Schedule.DateTime; eventAppointment.To = eventAppointment.From.AddHours(0.5); eventAppointment.EventName = Schedule.Service; eventAppointment.Color = Color.ForestGreen; EventsCollection.Add(eventAppointment); } } catch (Exception ex) { Error = ex; } finally { IsBusy = false; } if (Error != null) { await _pageDialogService.DisplayAlertAsync("Erro", Error.Message, "OK"); } } return; }
// Token: 0x06002A64 RID: 10852 RVA: 0x0013819C File Offset: 0x0013639C private static void smethod_6(EventsCollection eventsCollection_0, Song gclass27_0) { if (!GClass30.bool_0) { for (int i = 0; i < eventsCollection_0.Count; i++) { TextEvent textEvent = eventsCollection_0[i] as TextEvent; if (textEvent != null) { if (textEvent.Text.Contains("[section ") && !textEvent.Text.Contains("_ENDOFSONG")) { gclass27_0.method_0(new GClass22(textEvent.Text.Substring(9, textEvent.Text.Length - 10), (uint)textEvent.AbsoluteTime), false); } else if (textEvent.Text.Contains("[prc_")) { gclass27_0.method_0(new GClass22(textEvent.Text.Substring(5, textEvent.Text.Length - 6), (uint)textEvent.AbsoluteTime), false); } } } gclass27_0.method_15(); } }
private void LoadEvents(int type, bool updateRequested) { Device.BeginInvokeOnMainThread(async() => { IsBusy = true; try { cts.Token.ThrowIfCancellationRequested(); List <Models.Event> events = new List <Models.Event>(); if (Preferences.ContainsKey("events_key")) { var eventsSerialized = Preferences.Get("events_key", "null"); if (eventsSerialized is null || eventsSerialized.Length <= 0 || updateRequested) { //events = await App.EventManager.GetDataListAsync("event/type=" + type); events = await App.EventManager.GetDataListAsync("event"); eventsSerialized = JsonConvert.SerializeObject(events, Newtonsoft.Json.Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); Preferences.Set("events_key", eventsSerialized); events = events.FindAll(x => x.Type == type); } else { events = JsonConvert.DeserializeObject <List <Models.Event> >(eventsSerialized); events = events.FindAll(x => x.Type == type); } foreach (var item in events) { EventsCollection.Add(item); } //EventsCollection = new ObservableCollection<Models.Event>(events); } IsBusy = false; } catch (OperationCanceledException) { IsBusy = false; }