Files
windows/Media/TimelineMath.cs
ros d5e827112a Add MusicBridge protocol documentation and implement system volume control
- Created PROTOCOL.md to outline the MusicBridge protocol v1, detailing setup, TLS, pairing, state management, and command structure.
- Implemented SystemVolume class for managing system audio levels, including methods for setting, reading, changing, and muting volume.
- Added unit tests for the MusicBridge agent, covering pairing, identity storage, command validation, and media state management.
- Included tests for real-time media reading from Windows and ensured proper handling of artwork caching and retrieval.
2026-09-09 01:05:52 +03:00

17 lines
704 B
C#

namespace MusicBridge.Agent.Media;
internal static class TimelineMath
{
public static double Position(double position, double start, double end, bool playing,
DateTimeOffset updatedAt, DateTimeOffset now, double rate)
{
if (playing && updatedAt > DateTimeOffset.UnixEpoch && updatedAt <= now && double.IsFinite(rate))
position += (now - updatedAt).TotalSeconds * rate;
position = Math.Max(start, position);
return end > start ? Math.Min(end, position) : position;
}
public static (double Min, double Max) SeekRange(double start, double end, double min, double max)
=> (Math.Max(start, min), end > start ? Math.Min(end, max) : max);
}