Skip to content

Commit 36c08fb

Browse files
committed
Merge branch 'develop'
2 parents 27a6c9f + 751550e commit 36c08fb

34 files changed

Lines changed: 617 additions & 268 deletions

Source/MultiFunPlayer/Common/Extensions.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,18 @@ public static bool TryToObject<T>(this JToken token, JsonSerializer serializer,
3636
if (token.Type == JTokenType.Null)
3737
return false;
3838

39-
value = token.ToObject<T>(serializer);
40-
return value != null;
39+
#pragma warning disable CA2263 // Prefer generic overload when type is known
40+
if (token.ToObject(typeof(T), serializer) is T result)
41+
{
42+
value = result;
43+
return true;
44+
}
45+
else
46+
{
47+
value = default;
48+
return false;
49+
}
50+
#pragma warning restore CA2263 // Prefer generic overload when type is known
4151
}
4252
catch (JsonException)
4353
{

Source/MultiFunPlayer/Common/KeyframeCollection.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public sealed class KeyframeCollection : IReadOnlyList<Keyframe>
88

99
public KeyframeCollection() => _items = [];
1010
public KeyframeCollection(int capacity) => _items = new List<Keyframe>(capacity);
11+
public KeyframeCollection(IEnumerable<Keyframe> collection) => _items = new List<Keyframe>(collection.Order(KeyframePositionComparer.Default).DistinctBy(x => x.Position));
1112

1213
public void Add(Keyframe keyframe) => Add(keyframe.Position, keyframe.Value);
1314
public void Add(TimeSpan position, double value) => Add(position.TotalSeconds, value);
@@ -58,22 +59,22 @@ Keyframe TakeOrExtrapolate(int index, Keyframe p0, Keyframe p1)
5859
return Interpolation.Linear(p0.Position, p0.Value, p1.Position, p1.Value, position);
5960

6061
case InterpolationType.Pchip:
61-
{
62-
var pm1 = TakeOrExtrapolate(index - 1, p1, p0);
63-
var pp1 = TakeOrExtrapolate(index + 2, p0, p1);
62+
{
63+
var pm1 = TakeOrExtrapolate(index - 1, p1, p0);
64+
var pp1 = TakeOrExtrapolate(index + 2, p0, p1);
6465

65-
return Interpolation.Pchip(pm1.Position, pm1.Value, p0.Position, p0.Value, p1.Position, p1.Value, pp1.Position, pp1.Value, position);
66-
}
66+
return Interpolation.Pchip(pm1.Position, pm1.Value, p0.Position, p0.Value, p1.Position, p1.Value, pp1.Position, pp1.Value, position);
67+
}
6768

6869
case InterpolationType.Makima:
69-
{
70-
var pm1 = TakeOrExtrapolate(index - 1, p1, p0);
71-
var pm2 = TakeOrExtrapolate(index - 2, pm1, p1);
72-
var pp1 = TakeOrExtrapolate(index + 2, p0, p1);
73-
var pp2 = TakeOrExtrapolate(index + 3, p1, pp1);
70+
{
71+
var pm1 = TakeOrExtrapolate(index - 1, p1, p0);
72+
var pm2 = TakeOrExtrapolate(index - 2, pm1, p1);
73+
var pp1 = TakeOrExtrapolate(index + 2, p0, p1);
74+
var pp2 = TakeOrExtrapolate(index + 3, p1, pp1);
7475

75-
return Interpolation.Makima(pm2.Position, pm2.Value, pm1.Position, pm1.Value, p0.Position, p0.Value, p1.Position, p1.Value, pp1.Position, pp1.Value, pp2.Position, pp2.Value, position);
76-
}
76+
return Interpolation.Makima(pm2.Position, pm2.Value, pm1.Position, pm1.Value, p0.Position, p0.Value, p1.Position, p1.Value, pp1.Position, pp1.Value, pp2.Position, pp2.Value, position);
77+
}
7778

7879
case InterpolationType.Step:
7980
return Interpolation.Step(p0.Position, p0.Value, position);
@@ -138,7 +139,7 @@ public override bool Equals(object obj)
138139
public override int GetHashCode()
139140
{
140141
var result = new HashCode();
141-
foreach(var item in _items)
142+
foreach (var item in _items)
142143
result.Add(item.GetHashCode());
143144
return result.ToHashCode();
144145
}

Source/MultiFunPlayer/Input/IInputGesture.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,44 @@
11
namespace MultiFunPlayer.Input;
22

3-
internal interface IInputGesture
3+
public interface IInputGesture
44
{
55
IInputGestureDescriptor Descriptor { get; }
66
}
77

8-
internal interface ISimpleInputGesture : IInputGesture
8+
public interface IButtonInputGesture : IInputGesture
99
{
1010
bool State { get; }
1111
}
1212

13-
internal interface IAxisInputGesture : IInputGesture
13+
public interface IToggleInputGesture : IInputGesture
14+
{
15+
bool State { get; }
16+
bool IsInitialState { get; }
17+
}
18+
19+
public interface IAxisInputGesture : IInputGesture
1420
{
1521
public double Value { get; }
1622
public double Delta { get; }
1723
public double DeltaTime { get; }
1824
}
1925

20-
internal abstract class AbstractSimpleInputGesture(ISimpleInputGestureDescriptor descriptor, bool state) : ISimpleInputGesture
26+
internal abstract class AbstractButtonInputGesture(IButtonInputGestureDescriptor descriptor, bool state) : IButtonInputGesture
27+
{
28+
public IInputGestureDescriptor Descriptor { get; } = descriptor;
29+
public bool State { get; } = state;
30+
31+
public override bool Equals(object obj) => obj is IButtonInputGesture gesture && Descriptor.Equals(gesture.Descriptor);
32+
public override int GetHashCode() => HashCode.Combine(Descriptor);
33+
}
34+
35+
internal abstract class AbstractToggleInputGesture(IToggleInputGestureDescriptor descriptor, bool state, bool isInitialState) : IToggleInputGesture
2136
{
2237
public IInputGestureDescriptor Descriptor { get; } = descriptor;
2338
public bool State { get; } = state;
39+
public bool IsInitialState { get; } = isInitialState;
2440

25-
public override bool Equals(object obj) => obj is ISimpleInputGesture gesture && Descriptor.Equals(gesture.Descriptor);
41+
public override bool Equals(object obj) => obj is IToggleInputGesture gesture && Descriptor.Equals(gesture.Descriptor);
2642
public override int GetHashCode() => HashCode.Combine(Descriptor);
2743
}
2844

Source/MultiFunPlayer/Input/IInputGestureData.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
namespace MultiFunPlayer.Input;
22

33
public interface IInputGestureData;
4-
public interface ISimpleInputGestureData : IInputGestureData;
4+
public interface IEmptyInputGestureData : IInputGestureData;
5+
6+
public interface IToggleInputGestureData : IInputGestureData
7+
{
8+
bool State { get; }
9+
bool IsInitialState { get; }
10+
}
11+
512
public interface IAxisInputGestureData : IInputGestureData
613
{
714
double ValueOrDelta { get; }
@@ -12,9 +19,23 @@ public interface IAxisInputGestureData : IInputGestureData
1219
public double ApplyTo(double value, double deltaModifier = 1);
1320
}
1421

15-
internal sealed record SimpleInputGestureData : ISimpleInputGestureData
22+
internal sealed record EmptyInputGestureData : IEmptyInputGestureData
1623
{
17-
public static readonly SimpleInputGestureData Default = new();
24+
public static readonly EmptyInputGestureData Default = new();
25+
}
26+
27+
internal sealed record ToggleInputGestureData : IToggleInputGestureData
28+
{
29+
public bool State { get; }
30+
public bool IsInitialState { get; }
31+
32+
private ToggleInputGestureData(bool state, bool isInitialState)
33+
{
34+
State = state;
35+
IsInitialState = isInitialState;
36+
}
37+
38+
internal static ToggleInputGestureData FromGesture(IToggleInputGesture gesture) => new(gesture.State, gesture.IsInitialState);
1839
}
1940

2041
internal sealed record AxisInputGestureData : IAxisInputGestureData
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace MultiFunPlayer.Input;
22

3-
internal interface IInputGestureDescriptor;
4-
internal interface ISimpleInputGestureDescriptor : IInputGestureDescriptor;
5-
internal interface IAxisInputGestureDescriptor : IInputGestureDescriptor;
3+
public interface IInputGestureDescriptor;
4+
public interface IButtonInputGestureDescriptor : IInputGestureDescriptor;
5+
public interface IToggleInputGestureDescriptor : IInputGestureDescriptor;
6+
public interface IAxisInputGestureDescriptor : IInputGestureDescriptor;

Source/MultiFunPlayer/Input/RawInput/KeyboardGesture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace MultiFunPlayer.Input.RawInput;
44

5-
internal sealed record KeyboardGestureDescriptor : ISimpleInputGestureDescriptor
5+
internal sealed record KeyboardGestureDescriptor : IButtonInputGestureDescriptor
66
{
77
private static readonly IEqualityComparer<SortedSet<Key>> _comparer = SortedSet<Key>.CreateSetComparer();
88

@@ -16,7 +16,7 @@ internal sealed record KeyboardGestureDescriptor : ISimpleInputGestureDescriptor
1616
public override string ToString() => $"[Keyboard Keys: {string.Join(", ", Keys)}]";
1717
}
1818

19-
internal sealed class KeyboardGesture(KeyboardGestureDescriptor descriptor, bool state) : AbstractSimpleInputGesture(descriptor, state)
19+
internal sealed class KeyboardGesture(KeyboardGestureDescriptor descriptor, bool state) : AbstractButtonInputGesture(descriptor, state)
2020
{
2121
public IReadOnlyCollection<Key> Keys => descriptor.Keys;
2222

Source/MultiFunPlayer/Input/RawInput/MouseButtonGesture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
namespace MultiFunPlayer.Input.RawInput;
44

5-
internal sealed record MouseButtonGestureDescriptor(MouseButton Button) : ISimpleInputGestureDescriptor
5+
internal sealed record MouseButtonGestureDescriptor(MouseButton Button) : IButtonInputGestureDescriptor
66
{
77
public override string ToString() => $"[Mouse Button: {Button}]";
88
}
99

10-
internal sealed class MouseButtonGesture(MouseButtonGestureDescriptor descriptor, bool state) : AbstractSimpleInputGesture(descriptor, state)
10+
internal sealed class MouseButtonGesture(MouseButtonGestureDescriptor descriptor, bool state) : AbstractButtonInputGesture(descriptor, state)
1111
{
1212
public MouseButton Button => descriptor.Button;
1313

Source/MultiFunPlayer/Input/TCode/TCodeButtonGesture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
namespace MultiFunPlayer.Input.TCode;
22

3-
internal sealed record TCodeButtonGestureDescriptor(string Button) : ISimpleInputGestureDescriptor
3+
internal sealed record TCodeButtonGestureDescriptor(string Button) : IButtonInputGestureDescriptor
44
{
55
public override string ToString() => $"[TCode Button: {Button}]";
66
}
77

8-
internal sealed class TCodeButtonGesture(TCodeButtonGestureDescriptor descriptor, bool state) : AbstractSimpleInputGesture(descriptor, state)
8+
internal sealed class TCodeButtonGesture(TCodeButtonGestureDescriptor descriptor, bool state) : AbstractButtonInputGesture(descriptor, state)
99
{
1010
public string Button => descriptor.Button;
1111

Source/MultiFunPlayer/Input/XInput/GamepadButtonGesture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace MultiFunPlayer.Input.XInput;
44

5-
internal sealed record GamepadButtonGestureDescriptor : ISimpleInputGestureDescriptor
5+
internal sealed record GamepadButtonGestureDescriptor : IButtonInputGestureDescriptor
66
{
77
private static readonly IEqualityComparer<SortedSet<GamepadVirtualKey>> _comparer = SortedSet<GamepadVirtualKey>.CreateSetComparer();
88

@@ -22,7 +22,7 @@ public GamepadButtonGestureDescriptor(uint userIndex, IEnumerable<GamepadVirtual
2222
public override string ToString() => $"[Gamepad Buttons: {UserIndex}/{string.Join(", ", Buttons)}]";
2323
}
2424

25-
internal sealed class GamepadButtonGesture(GamepadButtonGestureDescriptor descriptor, bool state) : AbstractSimpleInputGesture(descriptor, state)
25+
internal sealed class GamepadButtonGesture(GamepadButtonGestureDescriptor descriptor, bool state) : AbstractButtonInputGesture(descriptor, state)
2626
{
2727
public uint UserIndex => descriptor.UserIndex;
2828
public IEnumerable<GamepadVirtualKey> Buttons => descriptor.Buttons;

Source/MultiFunPlayer/MediaSource/ViewModels/InternalMediaSource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected override async Task RunAsync(ConnectionType connectionType, Cancellati
8686
while (TryReadMessage(out var message))
8787
{
8888
if (message is MediaPlayPauseMessage playPauseMessage) { SetIsPlaying(playPauseMessage.ShouldBePlaying); }
89-
else if (message is MediaSeekMessage seekMessage && _currentItem != null) { SetPosition(seekMessage.Position.TotalSeconds); }
89+
else if (message is MediaSeekMessage seekMessage && _currentItem != null) { SetPosition(seekMessage.Position.TotalSeconds, forceSeek: true); }
9090
else if (message is MediaChangeSpeedMessage changeSpeedMessage) { SetSpeed(changeSpeedMessage.Speed); }
9191
else if (message is MediaChangePathMessage changePathMessage)
9292
{
@@ -131,7 +131,7 @@ protected override async Task RunAsync(ConnectionType connectionType, Cancellati
131131
if (_position > _duration)
132132
{
133133
if (IsLooping)
134-
SetPosition(0);
134+
SetPosition(0, forceSeek: true);
135135
else if (IsShuffling)
136136
PlayRandom();
137137
else

0 commit comments

Comments
 (0)