Exemplo n.º 1
0
        private async void MidiFileButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
        {
            var filename = await _fileDialogManager.OpenFile();

            if (filename == null)
            {
                return;
            }

            if (!_midiManager.IsMidiFile(filename))
            {
                Logger.Warning($"Not a midi file! Chosen file: {filename}");
                return;
            }

            if (!_owner.Instrument.OpenMidi(filename))
            {
                return;
            }
            MidiPlaybackSetButtonsDisabled(false);
            if (midiInputButton.Pressed)
            {
                midiInputButton.Pressed = false;
            }
        }
        private async void MidiFileButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
        {
            var filters  = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi"));
            var filename = await _fileDialogManager.OpenFile(filters);

            var instrumentEnt = _owner.Instrument.Owner;
            var instrument    = _owner.Instrument;

            ContainerHelpers.TryGetContainerMan(_owner.Instrument.Owner, out var conMan);

            var localPlayer = IoCManager.Resolve <IPlayerManager>().LocalPlayer;

            // The following checks are only in place to prevent players from playing MIDI songs locally.
            // There are equivalents for these checks on the server.

            if (string.IsNullOrEmpty(filename))
            {
                return;
            }

            // If we don't have a player or controlled entity, we return.
            if (localPlayer?.ControlledEntity == null)
            {
                return;
            }

            // If the instrument is handheld and we're not holding it, we return.
            if ((instrument.Handheld && (conMan == null ||
                                         conMan.Owner != localPlayer.ControlledEntity)))
            {
                return;
            }

            // We check that we're in range unobstructed just in case.
            if (!EntitySystem.Get <SharedInteractionSystem>()
                .InRangeUnobstructed(localPlayer.ControlledEntity.Transform.MapPosition,
                                     instrumentEnt.Transform.MapPosition, ignoredEnt: instrumentEnt))
            {
                return;
            }

            if (!_midiManager.IsMidiFile(filename))
            {
                Logger.Warning($"Not a midi file! Chosen file: {filename}");
                return;
            }

            MidiStopButtonOnPressed(null);
            await Timer.Delay(100);

            if (!_owner.Instrument.OpenMidi(filename))
            {
                return;
            }
            MidiPlaybackSetButtonsDisabled(false);
            if (midiInputButton.Pressed)
            {
                midiInputButton.Pressed = false;
            }
        }
Exemplo n.º 3
0
        private async void MidiFileButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
        {
            var filters  = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi"));
            var filename = await _fileDialogManager.OpenFile(filters);

            if (string.IsNullOrEmpty(filename))
            {
                return;
            }

            if (!_midiManager.IsMidiFile(filename))
            {
                Logger.Warning($"Not a midi file! Chosen file: {filename}");
                return;
            }

            MidiStopButtonOnPressed(null);
            await Timer.Delay(100);

            if (!_owner.Instrument.OpenMidi(filename))
            {
                return;
            }
            MidiPlaybackSetButtonsDisabled(false);
            if (midiInputButton.Pressed)
            {
                midiInputButton.Pressed = false;
            }
        }
Exemplo n.º 4
0
        private async void MidiFileButtonOnOnPressed(ButtonEventArgs obj)
        {
            var filters = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi"));

            await using var file = await _fileDialogManager.OpenFile(filters);

            // did the instrument menu get closed while waiting for the user to select a file?
            if (Disposed)
            {
                return;
            }

            // The following checks are only in place to prevent players from playing MIDI songs locally.
            // There are equivalents for these checks on the server.

            if (file == null)
            {
                return;
            }

            /*if (!_midiManager.IsMidiFile(filename))
             * {
             *  Logger.Warning($"Not a midi file! Chosen file: {filename}");
             *  return;
             * }*/

            if (!PlayCheck())
            {
                return;
            }

            MidiStopButtonOnPressed(null);
            await using var memStream = new MemoryStream((int) file.Length);
            // 100ms delay is due to a race condition or something idk.
            // While we're waiting, load it into memory.
            await Task.WhenAll(Timer.Delay(100), file.CopyToAsync(memStream));

            if (_owner.Instrument is not {
            } instrument ||
                !EntitySystem.Get <InstrumentSystem>().OpenMidi(instrument.Owner, memStream.GetBuffer().AsSpan(0, (int)memStream.Length), instrument))
            {
                return;
            }

            MidiPlaybackSetButtonsDisabled(false);
            if (InputButton.Pressed)
            {
                InputButton.Pressed = false;
            }
        }
Exemplo n.º 5
0
        private async void MidiFileButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
        {
            var filters  = new FileDialogFilters(new FileDialogFilters.Group("mid", "midi"));
            var filename = await _fileDialogManager.OpenFile(filters);

            // The following checks are only in place to prevent players from playing MIDI songs locally.
            // There are equivalents for these checks on the server.

            if (string.IsNullOrEmpty(filename))
            {
                return;
            }

            if (!_midiManager.IsMidiFile(filename))
            {
                Logger.Warning($"Not a midi file! Chosen file: {filename}");
                return;
            }

            if (!PlayCheck())
            {
                return;
            }

            MidiStopButtonOnPressed(null);
            await Timer.Delay(100);

            if (!_owner.Instrument.OpenMidi(filename))
            {
                return;
            }
            MidiPlaybackSetButtonsDisabled(false);
            if (_midiInputButton.Pressed)
            {
                _midiInputButton.Pressed = false;
            }
        }