Exemplo n.º 1
0
        //private double m_standardTextHeight;

        public WaveFormTimeTicksAdorner(FrameworkElement adornedElement, AudioPaneView view, AudioPaneViewModel viewModel)
            : base(adornedElement)
        {
            //m_standardTextHeight = -1;

            IsHitTestVisible = false;
            ClipToBounds     = true;

            m_AudioPaneView      = view;
            m_AudioPaneViewModel = viewModel;

            //MouseMove += OnAdornerMouseMove;
            //MouseLeave += OnAdornerMouseLeave;

            ResetBrushes();

            m_point1 = new Point(1, 1);
            m_point2 = new Point(1, 1);

            m_typeFace = new Typeface("Helvetica");

            m_culture = CultureInfo.GetCultureInfo("en-us");

            m_point3 = new Point(1, 1);

            m_rectRect = new Rect(1, 1, 1, 1);
        }
Exemplo n.º 2
0
 public StateData(PropertyChangedNotifyBase notifier, AudioPaneViewModel vm)
 {
     m_notifier  = notifier;
     m_viewModel = vm;
     Audio       = new StreamStateData(m_notifier, vm);
     Selection   = new SelectionStateData(m_notifier, vm);
 }
Exemplo n.º 3
0
        public AudioPanePlugin(
            ILoggerFacade logger,
            IRegionManager regionManager,
            [Import(typeof(IAudioPaneView), RequiredCreationPolicy = CreationPolicy.Shared, AllowDefault = false)]
            AudioPaneView audioPaneView,
            [Import(typeof(AudioPaneViewModel), RequiredCreationPolicy = CreationPolicy.Shared, AllowDefault = false)]
            AudioPaneViewModel audioPaneViewModel,
            [Import(typeof(IShellView), RequiredCreationPolicy = CreationPolicy.Shared, AllowDefault = false)]
            IShellView shellView)
        {
            m_Logger        = logger;
            m_RegionManager = regionManager;

            m_AudioPaneView      = audioPaneView;
            m_AudioPaneViewModel = audioPaneViewModel;

            m_ShellView = shellView;

            m_RegionManager.RegisterNamedViewWithRegion(RegionNames.AudioPane,
                                                        new PreferredPositionNamedView {
                m_viewInstance = m_AudioPaneView, m_viewName = @"ViewOf_" + RegionNames.AudioPane
            });

            //m_RegionManager.RegisterViewWithRegion(RegionNames.AudioPane, typeof(IAudioPaneView));

            //IRegion targetRegion = m_RegionManager.Regions[RegionNames.AudioPane];
            //targetRegion.Add(m_AudioPaneView);
            //targetRegion.Activate(m_AudioPaneView);

            //m_Logger.Log(@"AudioPanePlugin is initializing...", Category.Debug, Priority.Medium);
        }
Exemplo n.º 4
0
        public AudioSettings(AudioPaneViewModel viewModel)
        {
            ViewModel   = viewModel;
            DataContext = ViewModel;
            ViewModel.SelectVoiceTTS(Settings.Default.Audio_TTS_Voice);

            InitializeComponent();
        }
Exemplo n.º 5
0
        public WaveFormLoadingAdorner(FrameworkElement adornedElement, AudioPaneView view, AudioPaneViewModel viewModel)
            : base(adornedElement)
        {
            IsHitTestVisible = false;
            ClipToBounds     = true;

            m_AudioPaneView      = view;
            m_AudioPaneViewModel = viewModel;

            m_typeFace = new Typeface("Helvetica");

            m_culture = CultureInfo.GetCultureInfo("en-us");

            m_pointText = new Point(1, 1);
            m_rectRect  = new Rect(1, 1, 1, 1);

            ResetBrushes();
        }
Exemplo n.º 6
0
        public void drawChunkInfos(DrawingContext drawingContext,
                                   double hoffset, double heightAvailable, double widthAvailable, double bytesPerPixel
                                   , ScaleTransform trans)
        {
            //double xZoomed = imageAndDraw == null ? -1 : imageAndDraw.m_originalX * zoom;
            //double wZoomed = imageAndDraw == null ? -1 : imageAndDraw.m_originalW * zoom;

            Tuple <TreeNode, TreeNode> treeNodeSelection = m_AudioPaneViewModel.m_UrakawaSession.GetTreeNodeSelection();

            if (treeNodeSelection.Item1 != null && m_AudioPaneViewModel.State.Audio.PlayStreamMarkers != null)
            {
                //drawingContext.Pop(); //PushOpacity

                long   sumData     = 0;
                double pixelsLeft  = 0;
                double pixelsRight = 0;
                double widthChunk  = 0;

                m_marker_MouseOver_Left  = null;
                m_marker_MouseOver_Right = null;

#if USE_NORMAL_LIST
                foreach (TreeNodeAndStreamDataLength marker in m_AudioPaneViewModel.State.Audio.PlayStreamMarkers)
                {
#else
                LightLinkedList <TreeNodeAndStreamDataLength> .Item current = m_AudioPaneViewModel.State.Audio.PlayStreamMarkers.m_First;
                while (current != null)
                {
                    TreeNodeAndStreamDataLength marker = current.m_data;
#endif //USE_NORMAL_LIST
                    if (pixelsLeft > (hoffset + widthAvailable))
                    {
                        break;
                    }


                    //if (m_MousePosX >= 0)
                    //{
                    //    //long timeInLocalUnits = m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.
                    //    //    ConvertBytesToTime(
                    //    //        m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.
                    //    //            AdjustByteToBlockAlignFrameSize(
                    //    //                (long) Math.Round(m_AudioPaneView.BytesPerPixel*(hoffset + m_MousePosX))));


                    //    m_point1.X = m_MousePosX;
                    //    m_point1.Y = 0;

                    //    m_point2.X = m_MousePosX;
                    //    m_point2.Y = heightAvailable;

                    //    drawingContext.DrawLine(m_penTick, m_point1, m_point2);
                    //}

                    if (pixelsLeft > hoffset)
                    {
                        m_point1.X = pixelsLeft - hoffset;
                        m_point2.X = m_point1.X;
                        m_point1.Y = 0;
                        m_point2.Y = heightAvailable;
                        drawingContext.DrawLine(m_penPhrases, m_point1, m_point2);

                        if (marker == m_marker_MouseGrab_Left)
                        {
                            m_marker_MouseGrab_Left_X = m_point1.X;
                        }

                        bool mouseMatch = m_MousePosX > 0 &&
                                          m_MousePosX > m_point1.X - MOUSE_GRAB_OFFSET &&
                                          m_MousePosX < m_point1.X + MOUSE_GRAB_OFFSET;

                        bool highlightMark = mouseMatch || marker == m_marker_MouseGrab_Left;
                        if (highlightMark)
                        {
                            if (mouseMatch)
                            {
                                m_marker_MouseOver_Left = marker;
                            }

                            double pt1x = m_point1.X;

highlightMark_1:
                            double p1X = highlightMark ? pt1x : m_MousePosX;

                            m_point1.X = p1X - MOUSE_GRAB_OFFSET;
                            m_point2.X = m_point1.X;
                            drawingContext.DrawLine(!highlightMark ? m_penPhrases : m_penTick, m_point1, m_point2);

                            m_point1.X = p1X + MOUSE_GRAB_OFFSET;
                            m_point2.X = m_point1.X;
                            drawingContext.DrawLine(!highlightMark ? m_penPhrases : m_penTick, m_point1, m_point2);

                            if (highlightMark && marker == m_marker_MouseGrab_Left)
                            {
                                highlightMark = false;
                                goto highlightMark_1;
                            }
                        }
                    }

                    pixelsRight = (sumData + marker.m_LocalStreamDataLength) / bytesPerPixel;

                    if (pixelsRight > hoffset && pixelsRight < (hoffset + widthAvailable))
                    {
                        m_point1.X = pixelsRight - hoffset;
                        m_point2.X = m_point1.X;
                        m_point1.Y = 0;
                        m_point2.Y = heightAvailable;
                        drawingContext.DrawLine(m_penPhrases, m_point1, m_point2);

                        if (marker == m_marker_MouseGrab_Right)
                        {
                            m_marker_MouseGrab_Right_X = m_point1.X;
                        }

                        bool mouseMatch = m_MousePosX > 0 &&
                                          m_MousePosX > m_point1.X - MOUSE_GRAB_OFFSET &&
                                          m_MousePosX < m_point1.X + MOUSE_GRAB_OFFSET;

                        bool highlightMark = mouseMatch || marker == m_marker_MouseGrab_Right;

                        if (highlightMark)
                        {
                            if (mouseMatch)
                            {
                                m_marker_MouseOver_Right = marker;
                            }

                            double pt1x = m_point1.X;

highlightMark_2:
                            double p1X = highlightMark ? pt1x : m_MousePosX;

                            m_point1.X = p1X - MOUSE_GRAB_OFFSET;
                            m_point2.X = m_point1.X;
                            drawingContext.DrawLine(!highlightMark ? m_penPhrases : m_penTick, m_point1, m_point2);

                            m_point1.X = p1X + MOUSE_GRAB_OFFSET;
                            m_point2.X = m_point1.X;
                            drawingContext.DrawLine(!highlightMark ? m_penPhrases : m_penTick, m_point1, m_point2);

                            if (highlightMark && marker == m_marker_MouseGrab_Right)
                            {
                                highlightMark = false;
                                goto highlightMark_2;
                            }
                        }
                    }


                    widthChunk = pixelsRight - pixelsLeft;
                    if (pixelsRight > hoffset && pixelsLeft < (hoffset + widthAvailable))
                    {
                        if (widthChunk < 20)
                        {
                            sumData   += marker.m_LocalStreamDataLength;
                            pixelsLeft = pixelsRight;

#if !USE_NORMAL_LIST
                            current = current.m_nextItem;
#endif //USE_NORMAL_LIST

                            continue;
                        }

                        if (trans != null)
                        {
                            drawingContext.PushTransform(trans);
                        }


                        long timeInLocalUnits = m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.ConvertBytesToTime(
                            m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.AdjustByteToBlockAlignFrameSize(
                                (long)Math.Round(bytesPerPixel * (pixelsRight - pixelsLeft))));

                        double tickHeight = m_tickHeight;

                        double chunkWidthForText = widthChunk - tickHeight - tickHeight - 1;

                        //                        if (m_standardTextHeight <= 0)
                        //                        {
                        //                            var txt = new FormattedText("Test Height",
                        //                                                                  m_culture,
                        //                                                                  FlowDirection.LeftToRight,
                        //                                                                  m_typeFace,
                        //                                                                  12,
                        //                                                                  m_phraseBrush
                        //#if NET40
                        //, null, TextFormattingMode.Display
                        //#endif //NET40
                        //);
                        //                            m_standardTextHeight = txt.Height;
                        //                        }


                        string strTime = null;

                        if (marker.m_Tag1 == null || !(marker.m_Tag1 is string))
                        {
                            strTime       = AudioPaneViewModel.FormatTimeSpan_Units(timeInLocalUnits);
                            marker.m_Tag1 = strTime;
                        }
                        else
                        {
                            strTime = (string)marker.m_Tag1;
                        }

                        var formattedTextDuration = new FormattedText(
                            strTime,
                            m_culture,
                            FlowDirection.LeftToRight,
                            m_typeFace,
                            12 * (trans != null ? m_zoom : 1),
                            m_timeTextBrush
#if NET40
                            , null, TextFormattingMode.Display
#endif //NET40
                            );

                        double formattedTextDurationWidth  = formattedTextDuration.Width;
                        double formattedTextDurationHeight = formattedTextDuration.Height;
                        if (trans != null)
                        {
                            formattedTextDurationWidth  *= (1 / m_zoom);
                            formattedTextDurationHeight *= (1 / m_zoom);
                        }

                        formattedTextDuration.Trimming      = TextTrimming.CharacterEllipsis;
                        formattedTextDuration.MaxTextWidth  = chunkWidthForText * (trans != null ? m_zoom : 1);
                        formattedTextDuration.MaxTextHeight = (formattedTextDurationHeight + tickHeight) * (trans != null ? m_zoom : 1);

                        double horizontalMargin = m_horizontalMargin;

                        m_point3.X = pixelsLeft - hoffset + horizontalMargin + tickHeight;
                        if (m_point3.X < tickHeight)
                        {
                            widthChunk += m_point3.X;
                            m_point3.X  = tickHeight;
                        }

                        m_point3.Y = heightAvailable - (formattedTextDurationHeight * 2) - tickHeight - tickHeight - tickHeight;

                        double diff = (pixelsRight - hoffset) - widthAvailable;
                        if (diff > 0)
                        {
                            widthChunk -= diff;
                        }

                        double minW = Math.Min(formattedTextDurationWidth + horizontalMargin + horizontalMargin,
                                               widthChunk - tickHeight - tickHeight - 1);
                        if (minW > 0)
                        {
                            m_rectRect.X      = m_point3.X - horizontalMargin;
                            m_rectRect.Y      = m_point3.Y;
                            m_rectRect.Width  = minW;
                            m_rectRect.Height = formattedTextDurationHeight;

                            //if (drawingGroup != null)
                            //{
                            //    if (imageAndDraw == null
                            //        ||
                            //        (
                            //        m_rectRect.Left >= xZoomed
                            //        && m_rectRect.Left < xZoomed + wZoomed
                            //        ||
                            //        m_rectRect.Right > xZoomed
                            //        && m_rectRect.Right <= xZoomed + wZoomed
                            //        )
                            //        )
                            //    {
                            //        m_rectRect.X -= xZoomed;
                            //        if (m_rectRect.X <0)
                            //        {
                            //            m_rectRect.Width -= -m_rectRect.X;
                            //            m_rectRect.X = 0;
                            //        }
                            //        var rectGeo = new RectangleGeometry(m_rectRect);
                            //        rectGeo.Freeze();
                            //        var rectGeoDraw = new GeometryDrawing(m_renderBrush, null, rectGeo);
                            //        rectGeoDraw.Freeze();
                            //        drawingGroup.Children.Add(rectGeoDraw);

                            //        m_point4.X = m_point3.X;
                            //        m_point4.Y = m_point3.Y;
                            //        m_point4.X -= xZoomed;
                            //        if (m_point4.X >= 0)
                            //        {
                            //            var textGeo = formattedTextDuration.BuildGeometry(m_point4);
                            //            textGeo.Freeze();
                            //            var textGeoDraw = new GeometryDrawing(m_timeTextBrush, null, textGeo);
                            //            textGeoDraw.Freeze();
                            //            drawingGroup.Children.Add(textGeoDraw);
                            //        }
                            //    }
                            //}
                            //else
                            //{


                            if (trans != null)
                            {
                                m_point3.X *= m_zoom;
                                m_point3.Y *= m_zoom;

                                m_rectRect.X      *= m_zoom;
                                m_rectRect.Y      *= m_zoom;
                                m_rectRect.Width  *= m_zoom;
                                m_rectRect.Height *= m_zoom;
                            }


                            drawingContext.DrawRectangle(m_renderBrush, null, m_rectRect);

                            var clipGeo = new RectangleGeometry(m_rectRect);
                            clipGeo.Freeze();
                            drawingContext.PushClip(clipGeo);

                            drawingContext.DrawText(formattedTextDuration, m_point3);

                            drawingContext.Pop(); //PushClip
                            //}
                        }

                        if (chunkWidthForText <= 10)
                        {
                            sumData   += marker.m_LocalStreamDataLength;
                            pixelsLeft = pixelsRight;

#if !USE_NORMAL_LIST
                            current = current.m_nextItem;
#endif //USE_NORMAL_LIST

                            if (trans != null)
                            {
                                drawingContext.Pop();
                            }
                            continue;
                        }

                        //QualifiedName qName = marker.m_TreeNode.GetXmlElementQName();
                        //string imgAlt = null;
                        //if (qName != null && qName.LocalName.ToLower() == "img")
                        //{
                        //    XmlAttribute xmlAttr = marker.m_TreeNode.GetXmlProperty().GetAttribute("alt");
                        //    if (xmlAttr != null)
                        //    {
                        //        imgAlt = xmlAttr.Value;
                        //    }
                        //}
                        //string nodeTxt = !String.IsNullOrEmpty(imgAlt) ? imgAlt : marker.m_TreeNode.GetTextMediaFlattened(false);

                        string        strText       = null;
                        FlowDirection flowDirection = FlowDirection.LeftToRight;

                        if (marker.m_Tag2 == null || !(marker.m_Tag2 is string))
                        {
                            TreeNode.StringChunkRange range = marker.m_TreeNode.GetTextFlattened_();

                            if (range != null && range.First != null && !String.IsNullOrEmpty(range.First.Str))
                            {
                                if (range.First.Direction == TreeNode.TextDirection.RTL)
                                {
                                    flowDirection = FlowDirection.RightToLeft;
                                }

                                StringBuilder strBuilder = new StringBuilder(range.GetLength());
                                TreeNode.ConcatStringChunks(range, -1, strBuilder);

                                strBuilder.Replace("\r\n", "");
                                strBuilder.Replace("\n", "");
                                strBuilder.Replace(Environment.NewLine, "");

                                strText = strBuilder.ToString().Trim();

                                marker.m_Tag2 = strText;
                            }
                        }
                        else
                        {
                            strText = (string)marker.m_Tag2;
                        }

                        if (!string.IsNullOrEmpty(strText))
                        {
                            var formattedText = new FormattedText(strText,
                                                                  m_culture,
                                                                  flowDirection,
                                                                  m_typeFace,
                                                                  12 * (trans != null ? m_zoom : 1),
                                                                  m_phraseBrush
#if NET40
                                                                  , null, TextFormattingMode.Display
#endif //NET40
                                                                  );

                            formattedText.Trimming      = TextTrimming.CharacterEllipsis;
                            formattedText.MaxTextWidth  = chunkWidthForText * (trans != null ? m_zoom : 1);
                            formattedText.MaxTextHeight = (formattedTextDurationHeight + tickHeight) * (trans != null ? m_zoom : 1);

                            double formattedTextWidth  = formattedText.Width;
                            double formattedTextHeight = formattedText.Height;
                            if (trans != null)
                            {
                                formattedTextWidth  *= (1 / m_zoom);
                                formattedTextHeight *= (1 / m_zoom);
                            }
                            //FormattedText formattedTextDots = null;

                            m_point3.Y = heightAvailable - formattedTextDurationHeight - tickHeight - tickHeight;

                            minW = Math.Min(formattedTextWidth + horizontalMargin + horizontalMargin,
                                            widthChunk - tickHeight - tickHeight - 1);     //chunkWidthForText
                            if (minW > 0)
                            {
                                m_rectRect.X      = m_point3.X / m_zoom - horizontalMargin;
                                m_rectRect.Y      = m_point3.Y;
                                m_rectRect.Width  = minW;
                                m_rectRect.Height = formattedTextDurationHeight;

                                //if (drawingGroup != null)
                                //{
                                //    if (imageAndDraw == null
                                //        ||
                                //        (
                                //        m_rectRect.Left >= xZoomed
                                //        && m_rectRect.Left < xZoomed + wZoomed
                                //        ||
                                //        m_rectRect.Right > xZoomed
                                //        && m_rectRect.Right <= xZoomed + wZoomed
                                //        )
                                //        )
                                //    {
                                //        m_rectRect.X -= xZoomed;
                                //        if (m_rectRect.X < 0)
                                //        {
                                //            m_rectRect.Width -= -m_rectRect.X;
                                //            m_rectRect.X = 0;
                                //        }
                                //        var rectGeo = new RectangleGeometry(m_rectRect);
                                //        rectGeo.Freeze();
                                //        var rectGeoDraw = new GeometryDrawing(m_renderBrush, null, rectGeo);
                                //        rectGeoDraw.Freeze();
                                //        drawingGroup.Children.Add(rectGeoDraw);

                                //        m_point3.X -= xZoomed;
                                //        if (m_point3.X >= 0)
                                //        {
                                //            var textGeo = formattedText.BuildGeometry(m_point3);
                                //            textGeo.Freeze();
                                //            var textGeoDraw = new GeometryDrawing(m_phraseBrush, null, textGeo);
                                //            textGeoDraw.Freeze();
                                //            drawingGroup.Children.Add(textGeoDraw);
                                //        }
                                //    }
                                //}
                                //else
                                //{
                                //drawingContext.PushOpacity(0.6);


                                if (trans != null)
                                {
                                    //m_point3.X *= m_zoom; ==> X is "borrowed" from previous text render, already zoomed
                                    m_point3.Y *= m_zoom;

                                    m_rectRect.X      *= m_zoom;
                                    m_rectRect.Y      *= m_zoom;
                                    m_rectRect.Width  *= m_zoom;
                                    m_rectRect.Height *= m_zoom;
                                }


                                drawingContext.DrawRectangle(m_renderBrush, null, m_rectRect);

                                //Boolean mouseIn = m_MousePosX >= (pixelsLeft - hoffset) &&
                                //                  m_MousePosX < (pixelsRight - hoffset);
                                //if (mouseIn)
                                //{
                                //    //drawingContext.Pop(); //PushOpacity
                                //}
                                var clipGeo = new RectangleGeometry(m_rectRect);
                                clipGeo.Freeze();
                                drawingContext.PushClip(clipGeo);

                                drawingContext.DrawText(formattedText, m_point3);

                                drawingContext.Pop(); //PushClip

                                //if (!mouseIn)
                                //{
                                //    //drawingContext.Pop(); //PushOpacity
                                //}

                                //if (false && formattedText.Width >= minW)
                                //{
                                //    formattedTextDots = new FormattedText(" ...",
                                //                                      m_culture,
                                //                                      FlowDirection.LeftToRight,
                                //                                      m_typeFace,
                                //                                      12,
                                //                                      m_timeTextBrush
                                //    );
                                //}

                                //if (formattedTextDots != null && formattedTextDots.Width < minW)
                                //{
                                //    m_point3.X = m_rectRect.X + m_rectRect.Width - formattedTextDots.Width;
                                //    m_rectRect.X = m_point3.X;
                                //    m_rectRect.Width = formattedTextDots.Width;

                                //    drawingContext.DrawRectangle(m_renderBrush, null, m_rectRect);
                                //    drawingContext.DrawText(formattedTextDots, m_point3);
                                //}
                                //}
                            }
                        }

                        if (trans != null)
                        {
                            drawingContext.Pop();
                        }
                    }

                    sumData   += marker.m_LocalStreamDataLength;
                    pixelsLeft = pixelsRight;

#if USE_NORMAL_LIST
                }
#else
                    current = current.m_nextItem;
                }
#endif //USE_NORMAL_LIST
                //drawingContext.PushOpacity(0.6);
            }
        }
Exemplo n.º 7
0
        private void drawMouseOver(DrawingContext drawingContext, double hoffset, double heightAvailable, double widthAvailable, ScaleTransform trans)
        {
            if (m_MousePosX >= 0)
            {
                long timeInLocalUnits = m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.ConvertBytesToTime(
                    m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.AdjustByteToBlockAlignFrameSize(
                        (long)Math.Round(m_AudioPaneView.BytesPerPixel * (hoffset + m_MousePosX))));

                var formattedText = new FormattedText(
                    AudioPaneViewModel.FormatTimeSpan_Units(timeInLocalUnits),
                    m_culture,
                    FlowDirection.LeftToRight,
                    m_typeFace,
                    12 * (trans != null ? m_zoom : 1),
                    m_timeTextBrush
#if NET40
                    , null, TextFormattingMode.Display
#endif //NET40
                    );

                m_point1.X = m_MousePosX;
                m_point1.Y = 0;

                m_point2.X = m_MousePosX;
                m_point2.Y = heightAvailable;

                drawingContext.DrawLine(m_penTick, m_point1, m_point2);

                if (trans != null)
                {
                    drawingContext.PushTransform(trans);
                }

                double formattedTextWidth  = formattedText.Width;
                double formattedTextHeight = formattedText.Height;
                if (trans != null)
                {
                    formattedTextWidth  *= (1 / m_zoom);
                    formattedTextHeight *= (1 / m_zoom);
                }

                double xPos = Math.Max(5, m_MousePosX - formattedTextWidth / 2);
                xPos = Math.Min(xPos, widthAvailable - formattedTextWidth - 5);
                xPos = Math.Max(5, xPos);

                //drawingContext.Pop(); //PushOpacity

                m_point3.X = xPos;
                //m_point3.Y = heightAvailable - formattedText.Height - m_tickHeight;
                m_point3.Y = formattedTextHeight + m_tickHeight + m_tickHeight;


                m_rectRect.X      = m_point3.X - m_horizontalMargin;
                m_rectRect.Y      = m_point3.Y;
                m_rectRect.Width  = formattedTextWidth + m_horizontalMargin * 2;
                m_rectRect.Height = formattedTextHeight;

                if (trans != null)
                {
                    m_point3.X *= m_zoom;
                    m_point3.Y *= m_zoom;

                    m_rectRect.X      *= m_zoom;
                    m_rectRect.Y      *= m_zoom;
                    m_rectRect.Width  *= m_zoom;
                    m_rectRect.Height *= m_zoom;
                }

                drawingContext.DrawRectangle(m_renderBrush, m_penTick, m_rectRect);

                drawingContext.DrawText(formattedText, m_point3);

                if (trans != null)
                {
                    drawingContext.Pop();
                }
            }
        }
Exemplo n.º 8
0
        /* var brush = ColorBrushCache.Get(Colors.Red) { Opacity = 0.0 };
         * drawingContext.DrawRectangle(brush, null,
         *                               new Rect(new Point(0, 0),
         *                                        new Size(widthAvailable,
         *                                                 heightAvailable))); */

        /*if (m_MousePosX != -1)
         * {
         *
         *   var formattedTextTMP = new FormattedText(
         *       "test",
         *       CultureInfo.GetCultureInfo("en-us"),
         *       FlowDirection.LeftToRight,
         *       new Typeface("Helvetica"),
         *       12,
         *       Brushes.White
         *       );
         *   drawingContext.DrawRectangle(renderBrush, null,
         *                                new Rect(new Point(0, 0),
         *                                         new Size(widthAvailable,
         *                                                  m_tickHeight + m_tickHeight + formattedTextTMP.Height)));
         * }*/

        private void drawTimeRuler(DrawingContext drawingContext, double hoffset, double heightAvailable, double widthAvailable, ScaleTransform trans)
        {
            double widthAvailableWaveFormOnly =
                Math.Min(widthAvailable, m_AudioPaneViewModel.State.Audio.DataLength / m_AudioPaneView.BytesPerPixel);

            long   minorTickInterval_milliseconds = 1000; //1s minor ticks
            double minorTickInterval_pixels       =
                m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.ConvertTimeToBytes(minorTickInterval_milliseconds * AudioLibPCMFormat.TIME_UNIT) / m_AudioPaneView.BytesPerPixel;

            const double idealTickInterval = 20;

            bool tooSmall = minorTickInterval_pixels < idealTickInterval;
            bool tooLarge = minorTickInterval_pixels > idealTickInterval;

            bool needReAdjusting = false;

            if (tooSmall || tooLarge)
            {
                minorTickInterval_pixels = idealTickInterval;

                minorTickInterval_milliseconds =
                    m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.ConvertBytesToTime(
                        m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.AdjustByteToBlockAlignFrameSize(
                            (long)Math.Round(m_AudioPaneView.BytesPerPixel * minorTickInterval_pixels))) / AudioLibPCMFormat.TIME_UNIT;

                if (minorTickInterval_milliseconds > 0)
                {
                    if (minorTickInterval_milliseconds % 10 != 0)
                    {
                        minorTickInterval_milliseconds = (long)Math.Truncate(Math.Round(minorTickInterval_milliseconds / 10.0) * 10);
                        if (minorTickInterval_milliseconds > 0)
                        {
                            minorTickInterval_pixels =
                                m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.ConvertTimeToBytes(minorTickInterval_milliseconds * AudioLibPCMFormat.TIME_UNIT) / m_AudioPaneView.BytesPerPixel;
                        }
                        else
                        {
                            needReAdjusting = true;
                        }
                    }
                }
                else
                {
                    needReAdjusting = true;
                }
            }

            int numberOfEntireTicksHidden = (int)Math.Floor(hoffset / minorTickInterval_pixels);

            double firstTickX = minorTickInterval_pixels -
                                (hoffset - (numberOfEntireTicksHidden * minorTickInterval_pixels));

            //drawingContext.PushOpacity(0.6);

            int    count        = numberOfEntireTicksHidden;
            double currentTickX = firstTickX;

            while (currentTickX <= widthAvailableWaveFormOnly)
            {
                count++;

                if (count % 5 == 0)
                {
                    m_point1.X = currentTickX;
                    m_point1.Y = 0;

                    m_point2.X = currentTickX;
                    m_point2.Y = m_tickHeight * 2;

                    drawingContext.DrawLine(m_penTick, m_point1, m_point2);

                    if (trans != null)
                    {
                        drawingContext.PushTransform(trans);
                    }

                    long timeInLocalUnits = m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.ConvertBytesToTime(
                        m_AudioPaneViewModel.State.Audio.GetCurrentPcmFormat().Data.AdjustByteToBlockAlignFrameSize(
                            (long)Math.Round(m_AudioPaneView.BytesPerPixel * (hoffset + currentTickX))));

                    var formattedText = new FormattedText(
                        AudioPaneViewModel.FormatTimeSpan_Units(timeInLocalUnits),
                        m_culture,
                        FlowDirection.LeftToRight,
                        m_typeFace,
                        12 * (trans != null ? m_zoom : 1),
                        m_timeTextBrush
#if NET40
                        , null, TextFormattingMode.Display
#endif //NET40
                        );
                    double formattedTextWidth  = formattedText.Width;
                    double formattedTextHeight = formattedText.Height;
                    if (trans != null)
                    {
                        formattedTextWidth  *= (1 / m_zoom);
                        formattedTextHeight *= (1 / m_zoom);
                    }

                    double posX = currentTickX - formattedTextWidth / 2;

                    m_point3.X = posX;
                    m_point3.Y = m_tickHeight * 2;

                    m_rectRect.X      = m_point3.X - m_horizontalMargin;
                    m_rectRect.Y      = m_point3.Y;
                    m_rectRect.Width  = Math.Min(formattedTextWidth + m_horizontalMargin * 2, widthAvailableWaveFormOnly - m_rectRect.X);
                    m_rectRect.Height = formattedTextHeight;

                    if (trans != null)
                    {
                        m_point3.X *= m_zoom;
                        m_point3.Y *= m_zoom;

                        m_rectRect.X      *= m_zoom;
                        m_rectRect.Y      *= m_zoom;
                        m_rectRect.Width  *= m_zoom;
                        m_rectRect.Height *= m_zoom;
                    }

                    if (m_MousePosX != -1)
                    {
                        //drawingContext.Pop();

                        drawingContext.DrawRectangle(m_renderBrush, null, m_rectRect);

                        //drawingContext.PushOpacity(0.6);
                    }

                    var clipGeo = new RectangleGeometry(m_rectRect);
                    clipGeo.Freeze();
                    drawingContext.PushClip(clipGeo);

                    drawingContext.DrawText(formattedText, m_point3);

                    drawingContext.Pop();

                    if (trans != null)
                    {
                        drawingContext.Pop();
                    }
                }
                else
                {
                    m_point1.X = currentTickX;
                    m_point1.Y = 0;

                    m_point2.X = currentTickX;
                    m_point2.Y = m_tickHeight;

                    drawingContext.DrawLine(m_penTick, m_point1, m_point2);
                }

                currentTickX += minorTickInterval_pixels;
            }
        }
 public AudioTTSGeneratorAutoAdvance(AudioPaneViewModel viewModel, Dictionary <string, string> ttsVoiceMap)
 {
     m_viewModel   = viewModel;
     m_ttsVoiceMap = ttsVoiceMap;
 }
Exemplo n.º 10
0
 public SelectionStateData(PropertyChangedNotifyBase notifier, AudioPaneViewModel vm)
 {
     m_notifier  = notifier;
     m_viewModel = vm;
 }
Exemplo n.º 11
0
 public StreamStateData(PropertyChangedNotifyBase notifier, AudioPaneViewModel vm)
 {
     m_viewModel = vm;
     m_notifier  = notifier;
 }