1
0
mirror of https://github.com/SirusDoma/VoxCharger.git synced 2024-11-28 01:10:49 +01:00
VoxCharger/Sources/Events/EventCollection.cs

100 lines
2.5 KiB
C#
Raw Normal View History

2020-04-18 22:24:48 +02:00
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace VoxCharger
{
public class EventCollection : ICollection<Event>
{
private List<Event> _events = new List<Event>();
2020-04-18 22:24:48 +02:00
public int Count => _events.Count;
2020-04-18 22:24:48 +02:00
public bool IsReadOnly => false;
public EventCollection()
{
}
public Event[] this[int measure]
{
get => _events.FindAll((ev) => ev.Time.Measure == measure).ToArray();
2020-04-18 22:24:48 +02:00
}
public Event[] this[Time time]
{
get => _events.FindAll((ev) => ev.Time == time).ToArray();
set => _events.AddRange(value.Where(ev => ev != null).Select(ev => { ev.Time = time; return ev; }));
2020-04-18 22:24:48 +02:00
}
public Event.TimeSignature GetTimeSignature(int measure)
{
return GetTimeSignature(new Time(measure, 1, 0));
}
public Event.TimeSignature GetTimeSignature(Time time)
{
var timeSig = _events.LastOrDefault(ev =>
2020-04-18 22:24:48 +02:00
ev is Event.TimeSignature && (ev.Time == time || ev.Time.Measure < time.Measure)
) as Event.TimeSignature;
return timeSig != null ? timeSig : new Event.TimeSignature(time, 4, 4);
}
public Event.Bpm GetBpm(int measure)
2020-04-18 22:24:48 +02:00
{
return GetBpm(new Time(measure, 1, 0));
2020-04-18 22:24:48 +02:00
}
public Event.Bpm GetBpm(Time time)
2020-04-18 22:24:48 +02:00
{
return _events.LastOrDefault(ev =>
ev is Event.Bpm && (ev.Time == time || ev.Time.Measure < time.Measure)
) as Event.Bpm;
2020-04-18 22:24:48 +02:00
}
public void Add(Event ev)
{
if (ev != null)
_events.Add(ev);
2020-04-18 22:24:48 +02:00
}
public void Add(params Event[] ev)
{
_events.AddRange(new List<Event>(ev).FindAll(e => e != null));
2020-04-18 22:24:48 +02:00
}
public bool Remove(Event ev)
{
return _events.Remove(ev);
2020-04-18 22:24:48 +02:00
}
public bool Contains(Event ev)
{
return _events.Contains(ev);
2020-04-18 22:24:48 +02:00
}
public void CopyTo(Event[] events, int index)
{
_events.CopyTo(events, index);
2020-04-18 22:24:48 +02:00
}
public void Clear()
{
_events.Clear();
2020-04-18 22:24:48 +02:00
}
public IEnumerator<Event> GetEnumerator()
{
return _events.GetEnumerator();
2020-04-18 22:24:48 +02:00
}
IEnumerator IEnumerable.GetEnumerator()
{
return _events.GetEnumerator();
2020-04-18 22:24:48 +02:00
}
}
}