public static string CreateTimeStamp(TimeStamp stamp) { var totalMilliseconds = (long)(stamp.AsSeconds() * 1000); var hours = totalMilliseconds / 1000 / 60 / 60; var minutes = (totalMilliseconds - hours * 60 * 60 * 1000) / 1000 / 60; var seconds = (totalMilliseconds - minutes * 60 * 1000) / 1000; var mseconds = totalMilliseconds % 1000; return(string.Format("{0:00}:{1:00}:{2:00}:{3:000}", hours, minutes, seconds, mseconds)); }
public double AsSeconds() { return(End.AsSeconds() - Begin.AsSeconds()); }
public void Render(ShaderColorXY shader, RectangleF view, Size areaInPixels, TimeStamp offset) { var ringBuffer = _ringBuffer; // y per pixel var visibleY = -1 * view.Height / areaInPixels.Height; // find an appropriate zoom level for current view var level = -1; var zoomFactor = areaInPixels.Width / (double)view.Width; for (int i = _zoomLevels.Length - 1; i >= 0; i--) { if (zoomFactor < 1.0 / _zoomLevels[i]) { level = i; break; } } if (_level != level) { System.Diagnostics.Debug.WriteLine("Level: " + level); if (level == -1) { _ringBuffer.Length = _ringBuffer.Capacity; SetX(1); } else { _ringBuffer.Length = _ringBuffer.Capacity / _zoomLevels[level]; SetXTriangles(_zoomLevels[level]); } _level = level; } // leftSample is the first sample that is visible in the current View. // It will be shifted to the left though if it is older than the other signals. // This must be corrected. // So calculate the left sample index to be the one that sits on the reference time. // fill GL buffer with visible samples var shift = ((offset - Duration.Begin).AsSeconds() * SamplesPerSecond); var leftSample = (int)((Math.Max(0, view.Left)) + shift); // Now the sample count is no more correct. We have to subtract what we just added. var sampleCount = FillBuffer( level: level, offset: leftSample / (level == -1 ? 1 : _zoomLevels[level]), samples: (int)(Math.Max(0, view.Width + shift) / (level == -1 ? 1 : _zoomLevels[level])) ); // Render GL.BindBuffer(BufferTarget.ArrayBuffer, ringBuffer.VboX); GL.EnableVertexAttribArray(shader.AttributeX); GL.VertexAttribPointer(shader.AttributeX, 1, VertexAttribPointerType.Float, false, 4, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, ringBuffer.VboY); GL.EnableVertexAttribArray(shader.AttributeY); GL.VertexAttribPointer(shader.AttributeY, 1, VertexAttribPointerType.Float, false, 4, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, ringBuffer.Ebo); shader.SetShaderColor(LineColor); GL.LineWidth(Selected ? 3.0f : 1.0f); var trsl = Matrix4.CreateTranslation((float)(leftSample + ((-offset.AsSeconds() + _currentTime.AsSeconds()) * SamplesPerSecond) - _signalBuffer.Length), 0, 0); shader.SetTranslateMatrix(trsl); if (level == -1) { GL.DrawElements(BeginMode.LineStrip, sampleCount, DrawElementsType.UnsignedInt, new IntPtr(0)); } else { GL.DrawElements(BeginMode.TriangleStrip, sampleCount, DrawElementsType.UnsignedInt, new IntPtr(0)); } if (level != -1) { GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBufferMax.VboX); GL.EnableVertexAttribArray(shader.AttributeX); GL.VertexAttribPointer(shader.AttributeX, 1, VertexAttribPointerType.Float, false, 4, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBufferMax.VboY); GL.EnableVertexAttribArray(shader.AttributeY); GL.VertexAttribPointer(shader.AttributeY, 1, VertexAttribPointerType.Float, false, 4, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, _ringBufferMax.Ebo); shader.SetShaderColor(LineColor); GL.LineWidth(Selected ? 3.0f : 1.0f); trsl = Matrix4.CreateTranslation((float)(leftSample + ((-offset.AsSeconds() + _currentTime.AsSeconds()) * SamplesPerSecond) - _signalBuffer.Length), 0, 0); shader.SetTranslateMatrix(trsl); GL.DrawElements(BeginMode.LineStrip, sampleCount / 2, DrawElementsType.UnsignedInt, new IntPtr(0)); GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBufferMin.VboX); GL.EnableVertexAttribArray(shader.AttributeX); GL.VertexAttribPointer(shader.AttributeX, 1, VertexAttribPointerType.Float, false, 4, 0); GL.BindBuffer(BufferTarget.ArrayBuffer, _ringBufferMin.VboY); GL.EnableVertexAttribArray(shader.AttributeY); GL.VertexAttribPointer(shader.AttributeY, 1, VertexAttribPointerType.Float, false, 4, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, _ringBufferMin.Ebo); shader.SetShaderColor(LineColor); GL.LineWidth(Selected ? 3.0f : 1.0f); trsl = Matrix4.CreateTranslation((float)(leftSample + ((-offset.AsSeconds() + _currentTime.AsSeconds()) * SamplesPerSecond) - _signalBuffer.Length), 0, 0); shader.SetTranslateMatrix(trsl); GL.DrawElements(BeginMode.LineStrip, sampleCount / 2, DrawElementsType.UnsignedInt, new IntPtr(0)); } }