Exemplo n.º 1
0
        private static List <StoryboardObject> GetStoryboardObjectsFromOsb(string path, int level)
        {
            OsuFileReader reader = new OsuFileReader(path);

            VariableCollection collection = new VariableCollection(new VariableReader(reader).EnumValues());

            EventReader er = new EventReader(reader, collection);

            StoryboardReader StoryboardReader = new StoryboardReader(er);

            List <StoryboardObject> list;

            list = StoryboardReader.EnumValues().ToList();
            list.RemoveAll(c => c == null);

            foreach (var obj in list)
            {
                obj.CalculateAndApplyBaseFrameTime();
            }

            if (PlayerSetting.StoryboardObjectOptimzeLevel > 0)
            {
                if (!optimzer_add)
                {
                    InitOptimzerManager();
                }

                StoryboardOptimzerManager.Optimze(level, list);
            }

            return(list);
        }
Exemplo n.º 2
0
        private IEnumerable <StoryboardObject> GetObjects(byte[] data)
        {
            var stream = new MemoryStream(data);

            var reader = new OsuFileReader(stream);

            var collection = new VariableCollection(new VariableReader(reader).EnumValues());

            var er = new EventReader(reader, collection);

            var StoryboardReader = new StoryboardReader(er);

            var list = StoryboardReader.EnumValues().ToList();

            list.RemoveAll(c => c == null);

            foreach (var obj in list)
            {
                obj.CalculateAndApplyBaseFrameTime();
            }

            stream.Dispose();

            return(list);
        }
Exemplo n.º 3
0
        protected override void OnDisappearing()
        {
            base.OnDisappearing();
            // Moved marking _isPageDisappeared flag to very beginning.
            // OnPlayerStateChanged event handler may receive events accessing
            // _playerService while _playerService is being disposed/nullified
            // Not something we want...
            // Reproducible with fast playback start/exit before start completes.
            //
            _isPageDisappeared = true;

            Device.StartTimer(TimeSpan.FromMilliseconds(0), () =>
            {
                if (!_isPageDisappeared)
                {
                    return(false);
                }
                _storyboardReader?.Dispose();
                _seekLogic.StoryboardReader = null;
                _storyboardReader           = null;
                _subscriptions.Dispose();
                Player?.Dispose();
                Player = null;
                return(false);
            });
            MessagingCenter.Unsubscribe <IKeyEventSender, string>(this, "KeyDown");
        }
Exemplo n.º 4
0
 public void SetSeekPreviewReader(StoryboardReader storyboardReader, SeekLogic seekLogic)
 {
     _seekPreviewReader?.Dispose();
     _seekPreviewReader         = storyboardReader;
     seekLogic.StoryboardReader = _seekPreviewReader;
     DllImports.SetSeekPreviewCallback(_getSeekPreviewStoryboardDelegate);
     _seekLogic = seekLogic;
 }
Exemplo n.º 5
0
        private void SetSeekLogicAndSeekPreview()
        {
            _seekLogic.IsSeekInProgress = false;
            string           previewPath       = _resourceLoader.ContentList[_selectedTile].SeekPreviewPath;
            StoryboardReader seekPreviewReader = previewPath != null ? new StoryboardReader(previewPath) : null;

            StoryboardManager.GetInstance().SetSeekPreviewReader(seekPreviewReader, _seekLogic);
        }
Exemplo n.º 6
0
 public void SetUnfocus()
 {
     _isFocused = false;
     this.AbortAnimation("Animation");
     this.ScaleTo(1, 334);
     _storyboardReader?.Dispose();
     _storyboardReader = null;
     _previewBitmap    = null;
     InvalidateSurface();
 }
Exemplo n.º 7
0
        private void InitializeSeekPreview(string seekPreviewPath)
        {
            _storyboardReader?.Dispose();
            _storyboardReader =
                new StoryboardReader(Path.Combine(Application.Current.DirectoryInfo.Resource, seekPreviewPath));
            _seekLogic.StoryboardReader = _storyboardReader;

            var size = _storyboardReader.FrameSize;

            SeekPreviewCanvas.WidthRequest  = size.Width;
            SeekPreviewCanvas.HeightRequest = size.Height;
        }
Exemplo n.º 8
0
        private async void InitializeSeekPreview(string seekPreviewPath)
        {
            _storyboardReader?.Dispose();
            _storyboardReader           = new StoryboardReader(seekPreviewPath);
            _seekLogic.StoryboardReader = _storyboardReader;

            try
            {
                await _storyboardReader.LoadTask;

                var size = _storyboardReader.FrameSize;
                SeekPreviewCanvas.WidthRequest  = size.Width;
                SeekPreviewCanvas.HeightRequest = size.Height;
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }
        }
Exemplo n.º 9
0
        public void ResetFocus()
        {
            try
            {
                _animationCts?.Cancel();
            }
            catch (ObjectDisposedException)
            {
            }

            _isFocused = false;
            this.AbortAnimation("ScaleTo");
            this.AbortAnimation("Animation");
            this.ScaleTo(1);
            _storyboardReader?.Dispose();
            _storyboardReader = null;
            _previewBitmap    = null;
            InvalidateSurface();
        }
Exemplo n.º 10
0
        public static List <StoryboardObject> GetStoryboardObjectsFromFile(string path)
        {
            OsuFileReader reader = new OsuFileReader(path);

            VariableCollection collection = new VariableCollection(new VariableReader(reader).EnumValues());

            EventReader er = new EventReader(reader, collection);

            StoryboardReader StoryboardReader = new StoryboardReader(er);

            var list = StoryboardReader.EnumValues().OfType <StoryboardObject>().ToList();

            //计算每个物件的FrameStartTime
            foreach (var obj in list)
            {
                obj.CalculateAndApplyBaseFrameTime();
            }

            return(list);
        }
        static List <StoryboardObject> ParseStoryboardFile(Stream fileStream)
        {
            using var osbFileReader = new ReOsuStoryboardPlayer.Core.Parser.Stream.OsuFileReader(fileStream);
            var variables = new VariableCollection(new VariableReader(osbFileReader).EnumValues());
            var sbReader  = new StoryboardReader(new EventReader(osbFileReader, variables));

            var list = sbReader.EnumValues().OfType <StoryboardObject>().Select(x => {
                x.ImageFilePath = x.ImageFilePath.ToLower();
                return(x);
            }).ToList();

            foreach (var obj in list)
            {
                obj.CalculateAndApplyBaseFrameTime();
            }

            StoryboardOptimzerManager.Optimze(2857, list);

            return(list);
        }
Exemplo n.º 12
0
        public async void SetFocus()
        {
            _isFocused = true;
#pragma warning disable 4014
            this.ScaleTo(0.9);
#pragma warning restore 4014
            InvalidateSurface();

            if (ContentTilePreviewPath != null && _storyboardReader == null)
            {
                _storyboardReader = new StoryboardReader(Path.Combine(Application.Current.DirectoryInfo.Resource,
                                                                      ContentTilePreviewPath));
            }

            await Task.Delay(TimeSpan.FromMilliseconds(500));

            if (_storyboardReader == null || !_isFocused)
            {
                return;
            }

            var tilePreviewDuration = _storyboardReader.Duration();
            var animation           = new Animation
            {
                {
                    0, 1, new Animation(t =>
                    {
                        var position      = TimeSpan.FromMilliseconds(t);
                        var previewBitmap = _storyboardReader.GetFrame(position);
                        if (previewBitmap == null)
                        {
                            return;
                        }
                        _previewBitmap = previewBitmap;
                        InvalidateSurface();
                    }, 0,
                                        tilePreviewDuration.TotalMilliseconds)
                }
            };
            animation.Commit(this, "Animation", 1000 / 5, (uint)(tilePreviewDuration.TotalMilliseconds / 6), repeat: () => true);
        }
Exemplo n.º 13
0
        private DllImports.StoryboardData GetStoryboardDataImpl(long position, int tileId)
        {
            const float tilePreviewTimeScale = 10.0f / 3.0f;

            if (tileId != _tilePreviewReaderId)
            {
                _tilePreviewReaderId = tileId;
                _tilePreviewReader?.Dispose();
                if (_tilePreviewPath.ContainsKey(tileId))
                {
                    _tilePreviewReader = new StoryboardReader(
                        ResourceLoader.GetInstance().ContentList[tileId].TilePreviewPath,
                        StoryboardReader.PreloadingStrategy.PreloadOnlyRemoteSources);
                }
                else
                {
                    _tilePreviewReader = null;
                    return(GetStoryboardData());
                }
            }

            if (!_tilePreviewReader.LoadTask.IsCompletedSuccessfully)
            {
                return(GetStoryboardData(1));
            }

            var subSkBitmap = _tilePreviewReader.GetFrame(TimeSpan.FromMilliseconds(position) * tilePreviewTimeScale);

            if (subSkBitmap == null)
            {
                return(GetStoryboardData(1, 1, 0, new DllImports.SubBitmap(),
                                         (long)(_tilePreviewReader.Duration().TotalMilliseconds / tilePreviewTimeScale)));
            }

            return(GetStoryboardData(1, 1, 1, GetFrame(subSkBitmap),
                                     (long)(_tilePreviewReader.Duration().TotalMilliseconds / tilePreviewTimeScale)));
        }
Exemplo n.º 14
0
 public void UnloadTilePreview()
 {
     _tilePreviewReaderId = -1;
     _tilePreviewReader?.Dispose();
     _tilePreviewReader = null;
 }
Exemplo n.º 15
0
        public async void SetFocus()
        {
            using (_animationCts = new CancellationTokenSource())
            {
                var token = _animationCts.Token;
                try
                {
                    _isFocused = true;
                    this.AbortAnimation("ScaleTo");
                    await this.ScaleTo(0.9);

                    if (!_isFocused)
                    {
                        return;
                    }

                    InvalidateSurface();

                    if (ContentTilePreviewPath == null)
                    {
                        return;
                    }

                    if (_storyboardReader == null)
                    {
                        _storyboardReader = new StoryboardReader(ContentTilePreviewPath,
                                                                 StoryboardReader.PreloadingStrategy.PreloadOnlyRemoteSources);
                    }

                    await Task.WhenAll(Task.Delay(500), _storyboardReader.LoadTask).WaitAsync(token);

                    if (_storyboardReader == null || !_isFocused)
                    {
                        return;
                    }

                    var tilePreviewDuration = _storyboardReader.Duration();
                    var animation           = new Animation
                    {
                        {
                            0, 1, new Animation(t =>
                            {
                                var position      = TimeSpan.FromMilliseconds(t);
                                var previewBitmap = _storyboardReader.GetFrame(position);
                                if (previewBitmap == null)
                                {
                                    return;
                                }
                                _previewBitmap = previewBitmap;
                                InvalidateSurface();
                            }, 0,
                                                tilePreviewDuration.TotalMilliseconds)
                        }
                    };
                    animation.Commit(this, "Animation", 1000 / 5, (uint)(tilePreviewDuration.TotalMilliseconds / 6),
                                     repeat: () => true);
                }
                catch (TaskCanceledException)
                {
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);
                }
            }
        }