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>
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
private List<Event> _events = new List<Event>();
|
2020-04-18 22:24:48 +02:00
|
|
|
|
|
2023-01-06 14:58:29 +01: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]
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
get => _events.FindAll((ev) => ev.Time.Measure == measure).ToArray();
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Event[] this[Time time]
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
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)
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
public Event.Bpm GetBpm(int measure)
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
return GetBpm(new Time(measure, 1, 0));
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 14:58:29 +01:00
|
|
|
|
public Event.Bpm GetBpm(Time time)
|
2020-04-18 22:24:48 +02:00
|
|
|
|
{
|
2023-01-06 14:58:29 +01: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)
|
2023-01-06 14:58:29 +01:00
|
|
|
|
_events.Add(ev);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Add(params Event[] ev)
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
_events.AddRange(new List<Event>(ev).FindAll(e => e != null));
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Remove(Event ev)
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
return _events.Remove(ev);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool Contains(Event ev)
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
return _events.Contains(ev);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CopyTo(Event[] events, int index)
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
_events.CopyTo(events, index);
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Clear()
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
_events.Clear();
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerator<Event> GetEnumerator()
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
return _events.GetEnumerator();
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
|
|
|
{
|
2023-01-06 14:58:29 +01:00
|
|
|
|
return _events.GetEnumerator();
|
2020-04-18 22:24:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|