Beispiel #1
0
        public void RenderFrame(FastList <Note> notes, double midiTime, int finalCompositeBuff)
        {
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, finalCompositeBuff);

            GL.Viewport(0, 0, renderSettings.width, renderSettings.height);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.Clear(ClearBufferMask.DepthBufferBit);

            GL.Enable(EnableCap.Blend);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.Enable(EnableCap.Texture2D);

            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);

            GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);

            if (settings.fontName != font || settings.fontSize != fontSize || settings.fontStyle != fontStyle)
            {
                font      = settings.fontName;
                fontSize  = settings.fontSize;
                fontStyle = settings.fontStyle;
                textEngine.SetFont(font, fontStyle, fontSize);
            }
            if (!renderSettings.Paused)
            {
                polyphony    = 0;
                currentNotes = 0;
                long nc = 0;
                lock (notes)
                    foreach (Note n in notes)
                    {
                        nc++;
                        if (n.start < midiTime)
                        {
                            if (n.end > midiTime || !n.hasEnded)
                            {
                                polyphony++;
                            }
                            else if (n.meta != null)
                            {
                                n.delete = true;
                            }
                            if (n.meta == null)
                            {
                                currentNotes++;
                                noteCount++;
                                n.meta = true;
                            }
                        }
                        else if (n.start > midiTime)
                        {
                            break;
                        }
                    }
                LastNoteCount = nc;
                // notesHit.AddLast(currentNotes);
                notesHit.Add(currentNotes);
                while (notesHit.Count() > renderSettings.fps)
                {
                    notesHit.Pop();
                }
                nps = notesHit.Sum();
                if (Mnps < nps)
                {
                    Mnps = nps;
                }
                if (Mplph < polyphony)
                {
                    Mplph = polyphony;
                }
                frames++;
            }

            tempo = Tempo;

            seconds     = (int)Math.Floor((double)frames * 1000 / renderSettings.fps);
            totalsec    = (int)Math.Floor(CurrentMidi.secondsLength * 1000);
            totalframes = (int)Math.Ceiling(CurrentMidi.secondsLength * renderSettings.fps);
            if (seconds > totalsec)
            {
                seconds = totalsec;
            }
            time      = new TimeSpan(0, 0, 0, 0, seconds);
            totaltime = new TimeSpan(0, 0, 0, 0, totalsec);
            if (frames > totalframes)
            {
                frames = totalframes;
            }

            barDivide = (double)CurrentMidi.division * CurrentMidi.timeSig.numerator / CurrentMidi.timeSig.denominator * 4;

            limMidiTime = (long)midiTime;
            if (limMidiTime > CurrentMidi.tickLength)
            {
                limMidiTime = CurrentMidi.tickLength;
            }

            bar    = (long)Math.Floor(limMidiTime / barDivide) + 1;
            maxbar = (long)Math.Floor(CurrentMidi.tickLength / barDivide);
            if (bar > maxbar)
            {
                bar = maxbar;
            }

            renderText = settings.text;
            renderText = replace(renderText, settings.thousandSeparator);

            float   offset    = 0;
            Matrix4 transform = Matrix4.Identity;

            string[] lines = renderText.Split('\n');

            switch (settings.textAlignment)
            {
            case Alignments.TopLeft:
                transform = Matrix4.Mult(transform, Matrix4.CreateScale(scaleWidth, scaleHeight, 1.0f));
                transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(-1, 1, 0));
                transform = Matrix4.Mult(transform, Matrix4.CreateRotationZ(0));

                textEngine.Render(renderText, transform, White);
                break;

            case Alignments.TopRight:
                foreach (var line in lines)
                {
                    var size = textEngine.GetBoundBox(line);
                    // Matrix4 transform = Matrix4.Identity;
                    transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(-size.Width, offset, 0));
                    transform = Matrix4.Mult(transform, Matrix4.CreateScale(scaleWidth, scaleHeight, 1.0f));
                    transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(1, 1, 0));
                    transform = Matrix4.Mult(transform, Matrix4.CreateRotationZ(0));
                    offset   += size.Height;
                    textEngine.Render(line, transform, White);
                }
                break;

            case Alignments.BottomLeft:
                foreach (var line in lines.Reverse())
                {
                    var size = textEngine.GetBoundBox(line);
                    // Matrix4 transform = Matrix4.Identity;
                    transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(0, offset - size.Height, 0));
                    transform = Matrix4.Mult(transform, Matrix4.CreateScale(scaleWidth, scaleHeight, 1.0f));
                    transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(-1, -1, 0));
                    transform = Matrix4.Mult(transform, Matrix4.CreateRotationZ(0));
                    offset   -= size.Height;
                    textEngine.Render(line, transform, White);
                }
                break;

            case Alignments.BottomRight:
                foreach (var line in lines.Reverse())
                {
                    var size = textEngine.GetBoundBox(line);
                    // Matrix4 transform = Matrix4.Identity;
                    transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(-size.Width, offset - size.Height, 0));
                    transform = Matrix4.Mult(transform, Matrix4.CreateScale(scaleWidth, scaleHeight, 1.0f));
                    transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(1, -1, 0));
                    transform = Matrix4.Mult(transform, Matrix4.CreateRotationZ(0));
                    offset   -= size.Height;
                    textEngine.Render(line, transform, White);
                }
                break;

            default:
                int   p    = 1;
                float dist = 1.0f / (lines.Length + 1);
                switch (settings.textAlignment)
                {
                case Alignments.TopSpread:
                    foreach (var line in lines.Reverse())
                    {
                        var size = textEngine.GetBoundBox(line);
                        // Matrix4 transform = Matrix4.Identity;
                        transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(-size.Width / 2, 0, 0));
                        transform = Matrix4.Mult(transform, Matrix4.CreateScale(scaleWidth, scaleHeight, 1.0f));
                        transform = Matrix4.Mult(transform, Matrix4.CreateTranslation((dist * p++) * 2 - 1, 1, 0));
                        transform = Matrix4.Mult(transform, Matrix4.CreateRotationZ(0));
                        offset   -= size.Height;
                        textEngine.Render(line, transform, White);
                    }
                    break;

                case Alignments.BottomSpread:
                    foreach (var line in lines.Reverse())
                    {
                        var size = textEngine.GetBoundBox(line);
                        // Matrix4 transform = Matrix4.Identity;
                        transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(-size.Width / 2, -size.Height, 0));
                        transform = Matrix4.Mult(transform, Matrix4.CreateScale(scaleWidth, scaleHeight, 1.0f));
                        transform = Matrix4.Mult(transform, Matrix4.CreateTranslation((dist * p++) * 2 - 1, -1, 0));
                        transform = Matrix4.Mult(transform, Matrix4.CreateRotationZ(0));
                        offset   -= size.Height;
                        textEngine.Render(line, transform, White);
                    }
                    break;
                }
                break;
            }

            /*if (settings.textAlignment == Alignments.TopLeft)
             * {
             *  // var size = textEngine.GetBoundBox(renderText);
             *  // Matrix4 transform = Matrix4.Identity;
             *  transform = Matrix4.Mult(transform, Matrix4.CreateScale(1.0f / renderSettings.width, -1.0f / renderSettings.height, 1.0f));
             *  transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(-1, 1, 0));
             *  transform = Matrix4.Mult(transform, Matrix4.CreateRotationZ(0));
             *
             *  textEngine.Render(renderText, transform, Color4.White);
             * }*/
            /*else if (settings.textAlignment == Alignments.TopRight)
             * {
             *  // float offset = 0;
             *  // string[] lines = renderText.Split('\n');
             *  foreach (var line in lines)
             *  {
             *      var size = textEngine.GetBoundBox(line);
             *      // Matrix4 transform = Matrix4.Identity;
             *      transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(-size.Width, offset, 0));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateScale(1.0f / renderSettings.width, -1.0f / renderSettings.height, 1.0f));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(1, 1, 0));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateRotationZ(0));
             *      offset += size.Height;
             *      textEngine.Render(line, transform, Color4.White);
             *  }
             * }*/
            /*else if (settings.textAlignment == Alignments.BottomLeft)
             * {
             *  // float offset = 0;
             *  string[] lines = renderText.Split('\n');
             *  foreach (var line in lines.Reverse())
             *  {
             *      var size = textEngine.GetBoundBox(line);
             *      // Matrix4 transform = Matrix4.Identity;
             *      transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(0, offset - size.Height, 0));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateScale(1.0f / renderSettings.width, -1.0f / renderSettings.height, 1.0f));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(-1, -1, 0));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateRotationZ(0));
             *      offset -= size.Height;
             *      textEngine.Render(line, transform, Color4.White);
             *  }
             * }*/
            /*else if (settings.textAlignment == Alignments.BottomRight)
             * {
             *  // float offset = 0;
             *  string[] lines = renderText.Split('\n');
             *  foreach (var line in lines.Reverse())
             *  {
             *      var size = textEngine.GetBoundBox(line);
             *      // Matrix4 transform = Matrix4.Identity;
             *      transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(-size.Width, offset - size.Height, 0));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateScale(1.0f / renderSettings.width, -1.0f / renderSettings.height, 1.0f));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(1, -1, 0));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateRotationZ(0));
             *      offset -= size.Height;
             *      textEngine.Render(line, transform, Color4.White);
             *  }
             * }*/
            /*else if (settings.textAlignment == Alignments.TopSpread)
             * {
             *  // float offset = 0;
             *  string[] lines = renderText.Split('\n');
             *  float dist = 1.0f / (lines.Length + 1);
             *  int p = 1;
             *  foreach (var line in lines.Reverse())
             *  {
             *      var size = textEngine.GetBoundBox(line);
             *      // Matrix4 transform = Matrix4.Identity;
             *      transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(-size.Width / 2, 0, 0));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateScale(1.0f / renderSettings.width, -1.0f / renderSettings.height, 1.0f));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateTranslation((dist * p++) * 2 - 1, 1, 0));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateRotationZ(0));
             *      offset -= size.Height;
             *      textEngine.Render(line, transform, Color4.White);
             *  }
             * }*/
            /*else if (settings.textAlignment == Alignments.BottomSpread)
             * {
             *  // float offset = 0;
             *  string[] lines = renderText.Split('\n');
             *  float dist = 1.0f / (lines.Length + 1);
             *  int p = 1;
             *  foreach (var line in lines.Reverse())
             *  {
             *      var size = textEngine.GetBoundBox(line);
             *      // Matrix4 transform = Matrix4.Identity;
             *      transform = Matrix4.Mult(transform, Matrix4.CreateTranslation(-size.Width / 2, -size.Height, 0));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateScale(1.0f / renderSettings.width, -1.0f / renderSettings.height, 1.0f));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateTranslation((dist * p++) * 2 - 1, -1, 0));
             *      transform = Matrix4.Mult(transform, Matrix4.CreateRotationZ(0));
             *      offset -= size.Height;
             *      textEngine.Render(line, transform, Color4.White);
             *  }
             * }*/

            if (outputCsv != null)
            {
                outputCsv.WriteLine(replace(settings.csvFormat, Commas.Nothing));
            }

            GL.Disable(EnableCap.Blend);
            GL.Disable(EnableCap.Texture2D);
            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.ColorArray);
            GL.DisableClientState(ArrayCap.TextureCoordArray);

            GL.DisableVertexAttribArray(0);
            GL.DisableVertexAttribArray(1);
        }