2019-11-25 00:11:47 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Instruments;
|
2019-11-25 00:11:47 +01:00
|
|
|
using Robust.Client.Audio.Midi;
|
2020-08-13 14:40:27 +02:00
|
|
|
using Robust.Shared.Audio.Midi;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2019-11-25 00:11:47 +01:00
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
namespace Content.Client.Instruments;
|
2020-05-21 15:20:37 +02:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
[RegisterComponent, ComponentReference(typeof(SharedInstrumentComponent))]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class InstrumentComponent : SharedInstrumentComponent
|
2021-11-28 01:47:36 +01:00
|
|
|
{
|
|
|
|
|
public event Action? OnMidiPlaybackEnded;
|
2020-06-02 14:42:23 -04:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
public IMidiRenderer? Renderer;
|
2020-06-02 14:42:23 -04:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
public uint SequenceDelay;
|
2020-06-02 14:42:23 -04:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
public uint SequenceStartTick;
|
2020-06-02 14:42:23 -04:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
public TimeSpan LastMeasured = TimeSpan.MinValue;
|
2020-05-21 15:20:37 +02:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
public int SentWithinASec;
|
2020-05-18 13:29:31 +02:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// A queue of MidiEvents to be sent to the server.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public readonly List<MidiEvent> MidiEventBuffer = new();
|
2020-05-18 13:29:31 +02:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether a midi song will loop or not.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public bool LoopMidi { get; set; } = false;
|
2020-05-18 13:29:31 +02:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether this instrument is handheld or not.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
[DataField("handheld")]
|
|
|
|
|
public bool Handheld { get; set; } // TODO: Replace this by simply checking if the entity has an ItemComponent.
|
2020-06-02 14:42:23 -04:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether there's a midi song being played or not.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public bool IsMidiOpen => Renderer?.Status == MidiRendererStatus.File;
|
2020-05-18 13:29:31 +02:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the midi renderer is listening for midi input or not.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public bool IsInputOpen => Renderer?.Status == MidiRendererStatus.Input;
|
2020-06-02 14:42:23 -04:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Whether the midi renderer is alive or not.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
public bool IsRendererAlive => Renderer != null;
|
2020-06-02 14:42:23 -04:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
[ViewVariables]
|
|
|
|
|
public int PlayerTotalTick => Renderer?.PlayerTotalTick ?? 0;
|
2020-06-02 14:42:23 -04:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
[ViewVariables]
|
|
|
|
|
public int PlayerTick => Renderer?.PlayerTick ?? 0;
|
2020-06-02 14:42:23 -04:00
|
|
|
|
2021-11-28 01:47:36 +01:00
|
|
|
public void PlaybackEndedInvoke() => OnMidiPlaybackEnded?.Invoke();
|
2019-11-25 00:11:47 +01:00
|
|
|
}
|