SharedInstrumentComponent.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. using System.Collections;
  2. using Robust.Shared.Audio.Midi;
  3. using Robust.Shared.GameStates;
  4. using Robust.Shared.Serialization;
  5. namespace Content.Shared.Instruments;
  6. [NetworkedComponent]
  7. [Access(typeof(SharedInstrumentSystem))]
  8. public abstract partial class SharedInstrumentComponent : Component
  9. {
  10. [ViewVariables]
  11. public bool Playing { get; set; }
  12. [DataField("program"), ViewVariables(VVAccess.ReadWrite)]
  13. public byte InstrumentProgram { get; set; }
  14. [DataField("bank"), ViewVariables(VVAccess.ReadWrite)]
  15. public byte InstrumentBank { get; set; }
  16. [DataField("allowPercussion"), ViewVariables(VVAccess.ReadWrite)]
  17. public bool AllowPercussion { get; set; }
  18. [DataField("allowProgramChange"), ViewVariables(VVAccess.ReadWrite)]
  19. public bool AllowProgramChange { get ; set; }
  20. [DataField("respectMidiLimits"), ViewVariables(VVAccess.ReadWrite)]
  21. public bool RespectMidiLimits { get; set; } = true;
  22. [ViewVariables(VVAccess.ReadWrite)]
  23. public EntityUid? Master { get; set; } = null;
  24. [ViewVariables]
  25. public BitArray FilteredChannels { get; set; } = new(RobustMidiEvent.MaxChannels, true);
  26. }
  27. [Serializable, NetSerializable]
  28. public sealed class InstrumentComponentState : ComponentState
  29. {
  30. public bool Playing;
  31. public byte InstrumentProgram;
  32. public byte InstrumentBank;
  33. public bool AllowPercussion;
  34. public bool AllowProgramChange;
  35. public bool RespectMidiLimits;
  36. public NetEntity? Master;
  37. public BitArray FilteredChannels = default!;
  38. }
  39. /// <summary>
  40. /// This message is sent to the client to completely stop midi input and midi playback.
  41. /// </summary>
  42. [Serializable, NetSerializable]
  43. public sealed class InstrumentStopMidiEvent : EntityEventArgs
  44. {
  45. public NetEntity Uid { get; }
  46. public InstrumentStopMidiEvent(NetEntity uid)
  47. {
  48. Uid = uid;
  49. }
  50. }
  51. /// <summary>
  52. /// Send from the client to the server to set a master instrument.
  53. /// </summary>
  54. [Serializable, NetSerializable]
  55. public sealed class InstrumentSetMasterEvent : EntityEventArgs
  56. {
  57. public NetEntity Uid { get; }
  58. public NetEntity? Master { get; }
  59. public InstrumentSetMasterEvent(NetEntity uid, NetEntity? master)
  60. {
  61. Uid = uid;
  62. Master = master;
  63. }
  64. }
  65. /// <summary>
  66. /// Send from the client to the server to set a master instrument channel.
  67. /// </summary>
  68. [Serializable, NetSerializable]
  69. public sealed class InstrumentSetFilteredChannelEvent : EntityEventArgs
  70. {
  71. public NetEntity Uid { get; }
  72. public int Channel { get; }
  73. public bool Value { get; }
  74. public InstrumentSetFilteredChannelEvent(NetEntity uid, int channel, bool value)
  75. {
  76. Uid = uid;
  77. Channel = channel;
  78. Value = value;
  79. }
  80. }
  81. /// <summary>
  82. /// This message is sent to the client to start the synth.
  83. /// </summary>
  84. [Serializable, NetSerializable]
  85. public sealed class InstrumentStartMidiEvent : EntityEventArgs
  86. {
  87. public NetEntity Uid { get; }
  88. public InstrumentStartMidiEvent(NetEntity uid)
  89. {
  90. Uid = uid;
  91. }
  92. }
  93. /// <summary>
  94. /// This message carries a MidiEvent to be played on clients.
  95. /// </summary>
  96. [Serializable, NetSerializable]
  97. public sealed class InstrumentMidiEventEvent : EntityEventArgs
  98. {
  99. public NetEntity Uid { get; }
  100. public RobustMidiEvent[] MidiEvent { get; }
  101. public InstrumentMidiEventEvent(NetEntity uid, RobustMidiEvent[] midiEvent)
  102. {
  103. Uid = uid;
  104. MidiEvent = midiEvent;
  105. }
  106. }
  107. [NetSerializable, Serializable]
  108. public enum InstrumentUiKey
  109. {
  110. Key,
  111. }