Exemplo n.º 1
0
        internal TrackNode(
            AParentSceneNode parent,
            Transform transform,
            string label,
            TextureContent content,
            int id,
            SparseSampleByteStream videoStream,
            bool fillInEveryBeat,
            Func<float> levelRatioFunc,
            Func<Color> circleColorFunc,
            Func<Color> videoColorFunc,
            Func<Duration<Sample>> trackDurationFunc,
            Func<int> initialBeatFunc,
            Func<Color> beatColorFunc,
            Func<float> videoRateFunc)
            : base(parent, transform, label)
        {
            m_id = id;

            m_levelRatioFunc = levelRatioFunc;
            m_circleColorFunc = circleColorFunc;
            m_videoColorFunc = videoColorFunc;
            m_beatColorFunc = beatColorFunc;
            m_videoRateFunc = videoRateFunc;

            // create this first so it is Z-ordered behind m_soundNode
            m_selectNode = new SpriteNode(this, "TrackHighlight", content.FilledCircle);
            m_selectNode.Color = new Color((byte)0x80, (byte)0x80, (byte)0x80, (byte)0x80);
            m_selectNode.Origin = new Vector2(0.5f);

            m_soundNode = new SpriteNode(this, "TrackSound", content.FilledCircle);
            m_soundNode.Color = Color.Blue;
            m_soundNode.Origin = new Vector2(0.5f);

            m_videoNode = new SpriteNode(this, "Headshot", content.NewDynamicTexture(MagicNumbers.HeadCaptureSize, MagicNumbers.HeadCaptureSize));
            m_videoNode.Origin = new Vector2(0.5f);
            m_videoNode.LocalTransform = new Transform(new Vector2(0), new Vector2(MagicNumbers.HeadRatio));
            m_videoNode.SetSecondaryViewOption(SecondaryViewOption.TextureMirrored);

            m_videoStream = videoStream;

            m_beatNode = new BeatNode(
                this,
                // move it down a bit from the sprite node
                new Transform(new Vector2(0, 75)),
                "TrackBeats",
                fillInEveryBeat,
                MagicNumbers.MeasureCircleScale,
                trackDurationFunc,
                initialBeatFunc,
                beatColorFunc);

            m_beatNode.SetSecondaryViewOption(SecondaryViewOption.PositionMirrored);

            // we always mirror track node position
            SetSecondaryViewOption(SecondaryViewOption.PositionMirrored);

            m_lastVideoFrame = default(Slice<Frame, byte>);
        }
Exemplo n.º 2
0
        public void TestSparseSampleByteStream()
        {
            const int sliverSize = 2 * 2 * 4; // uncompressed 2x2 RGBA image... worst case
            const int bufferSlivers = 10;
            BufferAllocator<byte> allocator = new BufferAllocator<byte>(sliverSize * bufferSlivers, 1, sizeof(float));

            byte[] appendBuffer = new byte[sliverSize];
            for (int i = 0; i < sliverSize; i++) {
                appendBuffer[i] = (byte)i;
            }

            SparseSampleByteStream stream = new SparseSampleByteStream(10, allocator, sliverSize);
            stream.Append(11, new Slice<Frame, byte>(new Buf<byte>(-9, appendBuffer), sliverSize));

            // now let's get it back out
            Slice<Frame, byte> slice = stream.GetClosestSliver(11);
            HoloDebug.Assert(slice.Duration == 1);
            HoloDebug.Assert(slice.SliverSize == sliverSize);
            for (int i = 0; i < sliverSize; i++) {
                HoloDebug.Assert(slice[0, i] == (byte)i);
            }

            // now let's copy it to intptr
            byte[] target = new byte[sliverSize];
            unsafe {
                fixed (byte* p = target) {
                    IntPtr pp = new IntPtr(p);
                    stream.CopyTo(11, pp);
                }
            }

            for (int i = 0; i < sliverSize; i++) {
                HoloDebug.Assert(target[i] == (byte)i);
            }

            SparseSampleByteStream stream2 = new SparseSampleByteStream(10, allocator, sliverSize);
            unsafe {
                fixed (byte* p = target) {
                    IntPtr pp = new IntPtr(p);
                    stream2.Append(11, pp);
                }
            }

            Slice<Frame, byte> slice2 = stream2.GetClosestSliver(12);
            HoloDebug.Assert(slice2.Duration == 1);
            HoloDebug.Assert(slice2.SliverSize == sliverSize);
            for (int i = 0; i < sliverSize; i++) {
                HoloDebug.Assert(slice2[0, i] == (byte)i);
            }

            // now verify looping and shutting work as expected
            for (int i = 0; i < appendBuffer.Length; i++) {
                appendBuffer[i] += (byte)appendBuffer.Length;
            }
            stream2.Append(21, new Slice<Frame, byte>(new Buf<byte>(-10, appendBuffer), sliverSize));

            Slice<Frame, byte> slice3 = stream2.GetClosestSliver(12);
            HoloDebug.Assert(slice3.Duration == 1);
            HoloDebug.Assert(slice3.SliverSize == sliverSize);
            HoloDebug.Assert(slice3[0, 0] == (byte)0);
            Slice<Frame, byte> slice4 = stream2.GetClosestSliver(22);
            HoloDebug.Assert(slice4.Duration == 1);
            HoloDebug.Assert(slice4.SliverSize == sliverSize);
            HoloDebug.Assert(slice4[0, 0] == (byte)sliverSize);

            stream2.Shut((ContinuousDuration)20);

            // now the closest sliver to 32 should be the first sliver
            Slice<Frame, byte> slice5 = stream2.GetClosestSliver(32);
            HoloDebug.Assert(slice5.Duration == 1);
            HoloDebug.Assert(slice5.SliverSize == sliverSize);
            HoloDebug.Assert(slice5[0, 0] == (byte)0);
            // and 42, the second
            Slice<Frame, byte> slice6 = stream2.GetClosestSliver(42);
            HoloDebug.Assert(slice6.Duration == 1);
            HoloDebug.Assert(slice6.SliverSize == sliverSize);
            HoloDebug.Assert(slice6[0, 0] == (byte)sliverSize);
        }