public static void Free(StackObject *esp, FastList <object> mObjects) { if (esp->ObjectType == StackObjectType.Object) { mObjects.Pop(); } }
internal object Invoke(RuntimeMethod method, object instance, object[] parameters) { if (parameters == null) { parameters = Array <object> .Empty; } RuntimeInterpreter interpreter = null; lock (interpreters) { if (interpreters.Count > 0) { interpreter = interpreters.Pop(); } } if (interpreter == null) { interpreter = new RuntimeInterpreter(this); } try { return(interpreter.Invoke(method, instance, parameters)); } finally { lock (interpreters) { interpreters.Push(interpreter); } } }
void PlaybackLoop() { PlaybackEvent pe; int timeJump; long now; playbackLoopStarted = true; if (settings.ffRender) { return; } if (settings.Paused || !settings.playbackEnabled) { SpinWait.SpinUntil(() => !(settings.Paused || !settings.playbackEnabled)); } KDMAPI.ResetKDMAPIStream(); KDMAPI.SendDirectData(0x0); while (settings.running) { if (settings.Paused || !settings.playbackEnabled) { SpinWait.SpinUntil(() => !(settings.Paused || !settings.playbackEnabled)); } try { if (globalPlaybackEvents.ZeroLen) { continue; } pe = globalPlaybackEvents.Pop(); now = DateTime.Now.Ticks; if (now - 10000000 > frameStartTime) { SpinWait.SpinUntil(() => now - 10000000 < frameStartTime); } timeJump = (int)(((pe.pos - midiTime) * microsecondsPerTick / settings.tempoMultiplier - now + frameStartTime) / 10000); if (timeJump < -1000) { continue; } if (timeJump > 0) { Thread.Sleep(timeJump); } if (settings.playSound && settings.playbackEnabled) { try { KDMAPI.SendDirectData((uint)pe.val); } catch { continue; } } } catch { continue; } } KDMAPI.ResetKDMAPIStream(); KDMAPI.SendDirectData(0x0); }
public bool GetNextNote() { if (srcEnded) { return(false); } while (notesQueue.First == null || notesQueue.First.ended == false) { if (!ParseNextEv()) { return(false); } } content.Add(notesQueue.Pop()); return(true); }
public static IEnumerable <Note> Silhouette(this IEnumerable <Note> seq) { Queue <Note>[] unendedNotes = new Queue <Note> [256 * 16]; FastList <Note> notesQueue = new FastList <Note>(); for (int i = 0; i < unendedNotes.Length; i++) { unendedNotes[i] = new Queue <Note>(); } Queue <Note> queueFromNote(Note n) => unendedNotes[n.Key * 16 + n.Channel]; foreach (var n in seq) { var q = queueFromNote(n); if (q.Count == 0 || q.Last().End + 0.00000001 < n.Start) { var newNote = new Note(n.Channel, n.Key, 1, n.Start, n.End); q.Enqueue(newNote); notesQueue.Add(newNote); } else { q.Last().End = n.End; } if (!notesQueue.ZeroLen && queueFromNote(notesQueue.First).Count > 1) { queueFromNote(notesQueue.First).Dequeue(); yield return(notesQueue.Pop()); } } foreach (Note n in notesQueue) { yield return(n); } notesQueue.Unlink(); }
protected override void OnRenderFrame(FrameEventArgs e) { Task.Factory.StartNew(() => PlaybackLoop(), TaskCreationOptions.LongRunning); SpinWait.SpinUntil(() => playbackLoopStarted); Stopwatch watch = new Stopwatch(); watch.Start(); if (!settings.timeBasedNotes) { tempoFrameStep = ((double)midi.division / lastTempo) * (1000000.0 / settings.fps); } lock (render) { lastDeltaTimeOnScreen = render.renderer.NoteScreenTime; render.renderer.CurrentMidi = midi.info; } int noNoteFrames = 0; long lastNC = 0; bool firstRenderer = true; frameStartTime = DateTime.Now.Ticks; if (settings.timeBasedNotes) { microsecondsPerTick = 10000; } else { microsecondsPerTick = (long)((double)lastTempo / midi.division * 10); } while (settings.running && (noNoteFrames < settings.fps * 5 || midi.unendedTracks != 0)) { if (!settings.Paused || settings.forceReRender) { if (settings.lastyBGChangeTime != lastBGChangeTime) { if (settings.BGImage == null) { if (bgTexID != -1) { GL.DeleteTexture(bgTexID); } bgTexID = -1; } else { if (bgTexID == -1) { bgTexID = GL.GenTexture(); } loadImage(settings.BGImage, bgTexID, false, true); } } lock (render) { try { if (render.disposeQueue.Count != 0) { try { while (true) { var r = render.disposeQueue.Dequeue(); if (r.Initialized) { try { r.Dispose(); } catch { } GC.Collect(); } } } catch (InvalidOperationException) { } } if (!render.renderer.Initialized) { render.renderer.Init(); render.renderer.NoteColors = midi.tracks.Select(t => t.trkColors).ToArray(); render.renderer.ReloadTrackColors(); if (firstRenderer) { firstRenderer = false; midi.SetZeroColors(); } render.renderer.CurrentMidi = midi.info; lock (globalDisplayNotes) { foreach (Note n in globalDisplayNotes) { n.meta = null; } } } render.renderer.Tempo = 60000000.0 / lastTempo; lastDeltaTimeOnScreen = render.renderer.NoteScreenTime; if (settings.timeBasedNotes) { SpinWait.SpinUntil(() => (midi.currentFlexSyncTime > midiTime + lastDeltaTimeOnScreen + tempoFrameStep * settings.tempoMultiplier || midi.unendedTracks == 0) || !settings.running); } else { SpinWait.SpinUntil(() => (midi.currentSyncTime > midiTime + lastDeltaTimeOnScreen + tempoFrameStep * settings.tempoMultiplier || midi.unendedTracks == 0) || !settings.running); } if (!settings.running) { break; } render.renderer.RenderFrame(globalDisplayNotes, midiTime, finalCompositeBuff.BufferID); lastNC = render.renderer.LastNoteCount; if (lastNC == 0 && midi.unendedTracks == 0) { noNoteFrames++; } else { noNoteFrames = 0; } } catch (Exception ex) { MessageBox.Show("The renderer has crashed\n" + ex.Message); break; } } } double mv = 1; if (settings.realtimePlayback) { mv = (DateTime.Now.Ticks - frameStartTime) / microsecondsPerTick / tempoFrameStep; if (mv > settings.fps / 4) { mv = settings.fps / 4; } } lastMV = mv; lock (globalTempoEvents) { while (globalTempoEvents.First != null && midiTime + (tempoFrameStep * mv * settings.tempoMultiplier) > globalTempoEvents.First.pos) { var t = globalTempoEvents.Pop(); if (t.tempo == 0) { Console.WriteLine("Zero tempo event encountered, ignoring"); continue; } var _t = ((t.pos) - midiTime) / (tempoFrameStep * mv * settings.tempoMultiplier); mv *= 1 - _t; if (!settings.timeBasedNotes) { tempoFrameStep = ((double)midi.division / t.tempo) * (1000000.0 / settings.fps); } lastTempo = t.tempo; midiTime = t.pos; } } if (!settings.Paused) { midiTime += mv * tempoFrameStep * settings.tempoMultiplier; } frameStartTime = DateTime.Now.Ticks; if (settings.timeBasedNotes) { microsecondsPerTick = 10000; } else { microsecondsPerTick = (long)(lastTempo / midi.division * 10); } while (globalColorEvents.First != null && globalColorEvents.First.pos < midiTime) { var c = globalColorEvents.Pop(); var track = c.track; if (!settings.ignoreColorEvents) { if (c.channel == 0x7F) { for (int i = 0; i < 16; i++) { c.track.trkColors[i].left = c.col1; c.track.trkColors[i].right = c.col2; c.track.trkColors[i].isDefault = false; } } else { c.track.trkColors[c.channel].left = c.col1; c.track.trkColors[c.channel].right = c.col2; c.track.trkColors[c.channel].isDefault = false; } } } downscaleBuff.BindBuffer(); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, settings.width / settings.downscale, settings.height / settings.downscale); if (bgTexID != -1) { GL.UseProgram(postShaderFlip); GL.BindTexture(TextureTarget.Texture2D, bgTexID); DrawScreenQuad(); } if (settings.downscale > 1) { GL.UseProgram(postShaderDownscale); GL.Uniform1(uDownscaleFac, (int)settings.downscale); GL.Uniform2(uDownscaleRes, new Vector2(settings.width / settings.downscale, settings.height / settings.downscale)); } else { GL.UseProgram(postShader); } finalCompositeBuff.BindTexture(); DrawScreenQuad(); if (settings.ffRender) { if (!settings.ffRenderMask) { GL.UseProgram(postShader); } else { GL.UseProgram(postShaderMaskColor); } finalCompositeBuff.BindTexture(); ffmpegOutputBuff.BindBuffer(); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, settings.width / settings.downscale, settings.height / settings.downscale); downscaleBuff.BindTexture(); DrawScreenQuad(); IntPtr unmanagedPointer = Marshal.AllocHGlobal(pixels.Length); GL.ReadPixels(0, 0, settings.width / settings.downscale, settings.height / settings.downscale, PixelFormat.Bgra, PixelType.UnsignedByte, unmanagedPointer); Marshal.Copy(unmanagedPointer, pixels, 0, pixels.Length); if (lastRenderPush != null) { lastRenderPush.GetAwaiter().GetResult(); } lastRenderPush = Task.Run(() => { ffmpegvideo.StandardInput.BaseStream.Write(pixels, 0, pixels.Length); }); Marshal.FreeHGlobal(unmanagedPointer); if (settings.ffRenderMask) { if (lastRenderPushMask != null) { lastRenderPushMask.GetAwaiter().GetResult(); } GL.UseProgram(postShaderMask); ffmpegOutputBuff.BindBuffer(); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, settings.width / settings.downscale, settings.height / settings.downscale); downscaleBuff.BindTexture(); DrawScreenQuad(); unmanagedPointer = Marshal.AllocHGlobal(pixelsmask.Length); GL.ReadPixels(0, 0, settings.width / settings.downscale, settings.height / settings.downscale, PixelFormat.Bgra, PixelType.UnsignedByte, unmanagedPointer); Marshal.Copy(unmanagedPointer, pixelsmask, 0, pixelsmask.Length); if (lastRenderPush != null) { lastRenderPush.GetAwaiter().GetResult(); } lastRenderPush = Task.Run(() => { ffmpegmask.StandardInput.BaseStream.Write(pixelsmask, 0, pixelsmask.Length); }); Marshal.FreeHGlobal(unmanagedPointer); } } GL.UseProgram(postShader); GLPostbuffer.UnbindBuffers(); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, Width, Height); downscaleBuff.BindTexture(); DrawScreenQuad(); GLPostbuffer.UnbindTextures(); if (settings.ffRender) { VSync = VSyncMode.Off; } else if (settings.vsync) { VSync = VSyncMode.On; } else { VSync = VSyncMode.Off; } try { SwapBuffers(); } catch { break; } ProcessEvents(); double fr = 10000000.0 / watch.ElapsedTicks; settings.liveFps = (settings.liveFps * 2 + fr) / 3; watch.Reset(); watch.Start(); } Console.WriteLine("Left render loop"); settings.running = false; if (settings.ffRender) { if (lastRenderPush != null) { lastRenderPush.GetAwaiter().GetResult(); } ffmpegvideo.StandardInput.Close(); ffmpegvideo.Close(); if (settings.ffRenderMask) { if (lastRenderPushMask != null) { lastRenderPushMask.GetAwaiter().GetResult(); } ffmpegmask.StandardInput.Close(); ffmpegmask.Close(); } } Console.WriteLine("Disposing current renderer"); try { render.renderer.Dispose(); } catch { } try { Console.WriteLine("Disposing of other renderers"); while (render.disposeQueue.Count != 0) { var r = render.disposeQueue.Dequeue(); try { if (r.Initialized) { r.Dispose(); } } catch { } } } catch (InvalidOperationException) { } Console.WriteLine("Disposed of renderers"); globalDisplayNotes = null; globalTempoEvents = null; globalColorEvents = null; pixels = null; pixelsmask = null; if (settings.ffRender) { ffmpegvideo.Dispose(); if (settings.ffRenderMask) { ffmpegmask.Dispose(); } } ffmpegvideo = null; ffmpegmask = null; finalCompositeBuff.Dispose(); ffmpegOutputBuff.Dispose(); downscaleBuff.Dispose(); finalCompositeBuff = null; ffmpegOutputBuff = null; downscaleBuff = null; GL.DeleteBuffers(2, new int[] { screenQuadBuffer, screenQuadIndexBuffer }); GL.DeleteProgram(postShader); GL.DeleteProgram(postShaderMask); GL.DeleteProgram(postShaderMaskColor); GL.DeleteProgram(postShaderDownscale); midi = null; render = null; Console.WriteLine("Closing window"); this.Close(); }
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); }
protected override void OnRenderFrame(FrameEventArgs e) { Stopwatch watch = new Stopwatch(); watch.Start(); tempoFrameStep = ((double)midi.division / lastTempo) * (1000000 / settings.fps); lock (render) { lastDeltaTimeOnScreen = render.renderer.NoteScreenTime; } int noNoteFrames = 0; long lastNC = 0; while (settings.running && noNoteFrames < settings.fps * 5 || midi.unendedTracks != 0) { if (!settings.paused || settings.forceReRender) { lock (render) { try { if (render.disposeQueue.Count != 0) { try { while (true) { var r = render.disposeQueue.Dequeue(); if (r.Initialized) { r.Dispose(); } } } catch (InvalidOperationException) { } } if (!render.renderer.Initialized) { render.renderer.Init(); List <Color4[]> trkcolors = new List <Color4[]>(); foreach (var t in midi.tracks) { trkcolors.Add(t.trkColor); } render.renderer.SetTrackColors(trkcolors.ToArray()); lock (globalDisplayNotes) { foreach (Note n in globalDisplayNotes) { n.meta = null; } } } render.renderer.LastMidiTimePerTick = lastTempo / midi.division; lastDeltaTimeOnScreen = render.renderer.NoteScreenTime; SpinWait.SpinUntil(() => midi.currentSyncTime > midiTime + lastDeltaTimeOnScreen + tempoFrameStep || midi.unendedTracks == 0 || !settings.running); if (!settings.running) { break; } render.renderer.RenderFrame(globalDisplayNotes, midiTime, finalCompositeBuff.BufferID); lastNC = render.renderer.LastNoteCount; RenderAllText(lastNC); if (lastNC == 0 && midi.unendedTracks == 0) { noNoteFrames++; } else { noNoteFrames = 0; } } catch (Exception ex) { MessageBox.Show("The renderer has crashed\n" + ex.Message); break; } } } double mv = 1; lock (globalTempoEvents) { while (globalTempoEvents.First != null && midiTime + (tempoFrameStep * mv * settings.tempoMultiplier) > globalTempoEvents.First.pos) { var t = globalTempoEvents.Pop(); var _t = ((t.pos) - midiTime) / (tempoFrameStep * mv * settings.tempoMultiplier); mv *= 1 - _t; tempoFrameStep = ((double)midi.division / t.tempo) * (1000000.0 / settings.fps); lastTempo = t.tempo; midiTime = t.pos; } } if (!settings.paused) { midiTime += mv * tempoFrameStep * settings.tempoMultiplier; } while (globalColorEvents.First != null && globalColorEvents.First.pos < midiTime) { var c = globalColorEvents.Pop(); var track = c.track; if (c.channel == 0x7F) { for (int i = 0; i < 16; i++) { c.track.trkColor[i * 2] = c.col1; c.track.trkColor[i * 2 + 1] = c.col2; } } else { c.track.trkColor[c.channel * 2] = c.col1; c.track.trkColor[c.channel * 2 + 1] = c.col2; } } if (settings.ffRender) { finalCompositeBuff.BindBuffer(); IntPtr unmanagedPointer = Marshal.AllocHGlobal(pixels.Length); GL.ReadPixels(0, 0, settings.width, settings.height, PixelFormat.Rgb, PixelType.UnsignedByte, unmanagedPointer); Marshal.Copy(unmanagedPointer, pixels, 0, pixels.Length); if (lastRenderPush != null) { lastRenderPush.GetAwaiter().GetResult(); } lastRenderPush = Task.Run(() => ffmpeg.StandardInput.BaseStream.Write(pixels, 0, pixels.Length)); Marshal.FreeHGlobal(unmanagedPointer); } if (settings.imgRender) { finalCompositeBuff.BindBuffer(); IntPtr unmanagedPointer = Marshal.AllocHGlobal(pixels.Length); GL.ReadPixels(0, 0, settings.width, settings.height, PixelFormat.Bgra, PixelType.UnsignedByte, unmanagedPointer); if (lastRenderPush != null) { lastRenderPush.GetAwaiter().GetResult(); } lastRenderPush = Task.Run(() => { Bitmap output = new Bitmap(settings.width, settings.height, settings.width * 4, System.Drawing.Imaging.PixelFormat.Format32bppArgb, unmanagedPointer); output.RotateFlip(RotateFlipType.RotateNoneFlipY); output.Save(settings.imgPath + "\\img_" + imgnumber++ + ".png"); output.Dispose(); Marshal.FreeHGlobal(unmanagedPointer); }); } GL.UseProgram(postShader); GLPostbuffer.UnbindBuffers(); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, Width, Height); finalCompositeBuff.BindTexture(); DrawScreenQuad(); GLPostbuffer.UnbindTextures(); if (settings.ffRender) { VSync = VSyncMode.Off; } else if (settings.vsync) { VSync = VSyncMode.On; } else { VSync = VSyncMode.Off; } try { SwapBuffers(); } catch { break; } ProcessEvents(); double fr = 10000000.0 / watch.ElapsedTicks; settings.liveFps = (settings.liveFps * 2 + fr) / 3; watch.Reset(); watch.Start(); } settings.running = false; if (settings.ffRender) { if (lastRenderPush != null) { lastRenderPush.GetAwaiter().GetResult(); } ffmpeg.StandardInput.Close(); ffmpeg.Close(); } try { while (true) { var r = render.disposeQueue.Dequeue(); if (!r.Initialized) { r.Dispose(); } } } catch (InvalidOperationException) { } render.renderer.Dispose(); this.Close(); }
private void UndoDiscard(int column) { Pile discardPile = discardPiles.Pop(); upPiles[column].AddRange(discardPile); }