1
0

InstrumentComponent.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Content.Shared.Instruments;
  2. using Robust.Client.Audio.Midi;
  3. using Robust.Shared.Audio.Midi;
  4. namespace Content.Client.Instruments;
  5. [RegisterComponent]
  6. public sealed partial class InstrumentComponent : SharedInstrumentComponent
  7. {
  8. public event Action? OnMidiPlaybackEnded;
  9. [ViewVariables]
  10. public IMidiRenderer? Renderer;
  11. [ViewVariables]
  12. public uint SequenceDelay;
  13. [ViewVariables]
  14. public uint SequenceStartTick;
  15. [ViewVariables]
  16. public TimeSpan LastMeasured = TimeSpan.MinValue;
  17. [ViewVariables]
  18. public int SentWithinASec;
  19. /// <summary>
  20. /// A queue of MidiEvents to be sent to the server.
  21. /// </summary>
  22. [ViewVariables]
  23. public readonly List<RobustMidiEvent> MidiEventBuffer = new();
  24. /// <summary>
  25. /// Whether a midi song will loop or not.
  26. /// </summary>
  27. [ViewVariables(VVAccess.ReadWrite)]
  28. public bool LoopMidi { get; set; } = false;
  29. /// <summary>
  30. /// Whether this instrument is handheld or not.
  31. /// </summary>
  32. [DataField("handheld")]
  33. public bool Handheld { get; set; } // TODO: Replace this by simply checking if the entity has an ItemComponent.
  34. /// <summary>
  35. /// Whether there's a midi song being played or not.
  36. /// </summary>
  37. [ViewVariables]
  38. public bool IsMidiOpen => Renderer?.Status == MidiRendererStatus.File;
  39. /// <summary>
  40. /// Whether the midi renderer is listening for midi input or not.
  41. /// </summary>
  42. [ViewVariables]
  43. public bool IsInputOpen => Renderer?.Status == MidiRendererStatus.Input;
  44. /// <summary>
  45. /// Whether the midi renderer is alive or not.
  46. /// </summary>
  47. [ViewVariables]
  48. public bool IsRendererAlive => Renderer != null;
  49. [ViewVariables]
  50. public int PlayerTotalTick => Renderer?.PlayerTotalTick ?? 0;
  51. [ViewVariables]
  52. public int PlayerTick => Renderer?.PlayerTick ?? 0;
  53. public void PlaybackEndedInvoke() => OnMidiPlaybackEnded?.Invoke();
  54. }