using System; using System.Collections.Generic; using Content.Shared.Instruments; using Robust.Client.Audio.Midi; using Robust.Shared.Audio.Midi; using Robust.Shared.GameObjects; using Robust.Shared.Serialization.Manager.Attributes; using Robust.Shared.ViewVariables; namespace Content.Client.Instruments; [RegisterComponent, ComponentReference(typeof(SharedInstrumentComponent))] public sealed class InstrumentComponent : SharedInstrumentComponent { public event Action? OnMidiPlaybackEnded; public IMidiRenderer? Renderer; public uint SequenceDelay; public uint SequenceStartTick; public TimeSpan LastMeasured = TimeSpan.MinValue; public int SentWithinASec; /// /// A queue of MidiEvents to be sent to the server. /// [ViewVariables] public readonly List MidiEventBuffer = new(); /// /// Whether a midi song will loop or not. /// [ViewVariables(VVAccess.ReadWrite)] public bool LoopMidi { get; set; } = false; /// /// Whether this instrument is handheld or not. /// [ViewVariables] [DataField("handheld")] public bool Handheld { get; set; } // TODO: Replace this by simply checking if the entity has an ItemComponent. /// /// Whether there's a midi song being played or not. /// [ViewVariables] public bool IsMidiOpen => Renderer?.Status == MidiRendererStatus.File; /// /// Whether the midi renderer is listening for midi input or not. /// [ViewVariables] public bool IsInputOpen => Renderer?.Status == MidiRendererStatus.Input; /// /// Whether the midi renderer is alive or not. /// [ViewVariables] public bool IsRendererAlive => Renderer != null; [ViewVariables] public int PlayerTotalTick => Renderer?.PlayerTotalTick ?? 0; [ViewVariables] public int PlayerTick => Renderer?.PlayerTick ?? 0; public void PlaybackEndedInvoke() => OnMidiPlaybackEnded?.Invoke(); }