Пример #1
0
        public void DrawTimeAxis()
        {
            this.Controls.Clear();
            this.Controls.Add(lblTimeFreqPoint);
            timeTicks.Clear();
            timeLabels.Clear();

            float projectionWidth = this.Width - SpectrogramViewer.PADDING_LEFT;

            double[] timeEnds = parent.GetTimeEndsInView();
            if (timeEnds == null)
            {
                return;
            }
            long startMilliseconds = (long)timeEnds[0];
            long endMilliseconds   = (long)timeEnds[1];

            if (startMilliseconds == endMilliseconds)
            {
                return;
            }
            long        timespan         = endMilliseconds - startMilliseconds;
            List <long> timeStampSamples = new List <long>();
            int         timeStampSize;

            if (timespan <= 100)
            {
                timeStampSize = 10;
            }
            else if (timespan > 100 && timespan <= 500)
            {
                timeStampSize = 50;
            }
            else if (timespan > 500 && timespan <= 1000)
            {
                timeStampSize = 100;
            }
            else if (timespan > 1000 && timespan <= 2000)
            {
                timeStampSize = 250;
            }
            else if (timespan > 2000 && timespan <= 5000)
            {
                timeStampSize = 500;
            }
            else if (timespan > 5000 && timespan <= 10000)
            {
                timeStampSize = 1000;
            }
            else if (timespan > 10000 && timespan <= 30000)
            {
                timeStampSize = 2000;
            }
            else if (timespan > 30000 && timespan <= 80000)
            {
                timeStampSize = 5000;
            }
            else if (timespan > 80000 && timespan <= 180000)
            {
                timeStampSize = 15000;
            }
            else if (timespan > 180000 && timespan <= 360000)
            {
                timeStampSize = 30000;
            }
            else
            {
                timeStampSize = 60000;
            }

            int  numTimeStamps       = (int)(timespan / timeStampSize);
            long endRemainder        = endMilliseconds % timeStampSize;
            long currentMilliseconds = endMilliseconds - endRemainder;

            timeStampSamples.Add(currentMilliseconds);

            for (int i = 0; i < numTimeStamps; i++)
            {
                currentMilliseconds -= timeStampSize;
                timeStampSamples.Add(currentMilliseconds);
            }

            for (int i = 0; i < timeStampSamples.Count; i++)
            {
                double   timeStampPos = (double)(timeStampSamples[i] - startMilliseconds) / timespan;
                double   seconds      = (double)timeStampSamples[i] / 1000;
                TimeSpan t            = TimeSpan.FromSeconds(seconds);
                Label    timeStamp    = new Label();
                timeStamp.TextAlign = ContentAlignment.MiddleCenter;
                timeStamp.Top       = this.Height - 20;
                timeStamp.Left      = SpectrogramViewer.PADDING_LEFT + (int)(projectionWidth * timeStampPos) - timeStamp.Width / 2;
                timeStamp.Text      = t.ToString(@"m\:ss\:fff");
                timeStamp.Font      = new Font(Form1.fonts.Families[0], 7.8F, FontStyle.Regular, GraphicsUnit.Point);
                this.Controls.Add(timeStamp);
                timeLabels.Add(timeStamp);

                Rectangle primaryTick = new Rectangle(timeStamp.Left + timeStamp.Width / 2, this.Height - 25, 1, 10);

                if (timeTicks.Count > 0)
                {
                    Rectangle secondaryTick = new Rectangle((timeTicks[i * 2 - 2].X + primaryTick.X) / 2, this.Height - 25, 1, 5);
                    timeTicks.Add(secondaryTick);
                }
                timeTicks.Add(primaryTick);
            }

            if (timeStampSamples.Count > 1)
            {
                if (timeStampSamples[0] - startMilliseconds >= (timeStampSamples[1] - timeStampSamples[0]) / 2)
                {
                    Rectangle secondaryTick = new Rectangle(timeTicks[0].X - (timeTicks[1].X - timeTicks[0].X), this.Height - 25, 1, 5);
                    timeTicks.Add(secondaryTick);
                }

                if (endMilliseconds - timeStampSamples[timeStampSamples.Count - 1] >= (timeStampSamples[timeStampSamples.Count - 1] - timeStampSamples[timeStampSamples.Count - 2]) / 2)
                {
                    Rectangle secondaryTick = new Rectangle(timeTicks[timeTicks.Count - 1].X + (timeTicks[1].X - timeTicks[0].X), this.Height - 25, 1, 5);
                    timeTicks.Add(secondaryTick);
                }
            }
        }