Example #1
0
        public ChordOptions GetOptionsForLine(int index)
        {
            ChordOptions co = new ChordOptions();

            if (index >= 0 && index < Count)
            {
                for (int i = 0; i <= index; i++)
                {
                    ILineItem lineItem = GetLine(i);
                    if (lineItem is ChordOptions)
                    {
                        co = (ChordOptions)lineItem;
                    }
                }
            }
            return(co);
        }
Example #2
0
        public void CopyTo(ChordOptions co)
        {
            if (null == co)
            {
                throw new ArgumentNullException("co");
            }

            co.Width          = this.Width;
            co.Height         = this.Height;
            co.StrokeWidth    = this.StrokeWidth;
            co.Margin         = this.Margin;
            co.FontSize       = this.FontSize;
            co.FontFamily     = this.FontFamily;
            co.FontStyle      = this.FontStyle;
            co.BarreType      = this.BarreType;
            co.OpenStringType = this.OpenStringType;
            co.FullBarres     = this.FullBarres;
        }
Example #3
0
        public string ToSvg(ChordOptions chordOptions)
        {
            StringBuilder sb = new StringBuilder("");

            // Chart Title
            if (!String.IsNullOrEmpty(Title))
            {
                string chord            = Title[0].ToString();
                string chordModifier    = Title.Substring(1);
                double modifierFontSize = chordOptions.FontSize * 0.75;

                string title = chord + String.Format(TSPAN, modifierFontSize, chordModifier);

                string fontStyle = "";

                if (chordOptions.FontStyle == FontStyle.Bold ||
                    chordOptions.FontStyle == FontStyle.BoldItalic)
                {
                    fontStyle += "font-weight:bold;";
                }

                if (chordOptions.FontStyle == FontStyle.Italic ||
                    chordOptions.FontStyle == FontStyle.BoldItalic)
                {
                    fontStyle += "font-style:italic;";
                }

                double titleX = chordOptions.Width / 2.0;
                double titleY = chordOptions.Margin + (chordOptions.FontSize / 2.0);

                sb.AppendFormat(TEXT,
                                chordOptions.FontSize,
                                chordOptions.FontFamily,
                                fontStyle,
                                "middle",
                                titleX,
                                titleY,
                                title);
            }

            //TODO Add option to remove title spacing when title is absent
            double titleHeight = chordOptions.FontSize;

            // Rect
            double rectWidth  = chordOptions.Width - (2.0 * chordOptions.Margin);
            double rectHeight = chordOptions.Height - titleHeight - (2.0 * chordOptions.Margin);
            double rectX      = chordOptions.Margin;
            double rectY      = chordOptions.Margin + titleHeight;

            sb.AppendFormat(BASE,
                            chordOptions.StrokeWidth,
                            rectWidth,
                            rectHeight,
                            rectX,
                            rectY);

            // Vertical Lines
            double vSpacing = rectWidth / (NumStrings - 1);

            for (int vLine = 1; vLine < NumStrings - 1; vLine++)
            {
                double x  = rectX + (vLine * vSpacing);
                double y1 = rectY;
                double y2 = y1 + rectHeight;
                sb.AppendFormat(LINE,
                                chordOptions.StrokeWidth,
                                x,
                                y1,
                                x,
                                y2);
            }

            // Horizontal Lines
            double hSpacing = rectHeight / NumFrets;

            for (int hLine = 1; hLine < NumFrets; hLine++)
            {
                double x1 = rectX;
                double x2 = rectX + rectWidth;
                double y  = rectY + (hLine * hSpacing);

                sb.AppendFormat(LINE,
                                chordOptions.StrokeWidth,
                                x1,
                                y,
                                x2,
                                y);
            }

            double strokeCorrection = chordOptions.StrokeWidth / 2.0;
            double markRadius       = Math.Min(vSpacing, hSpacing) / 3.0;
            double muteRadius       = markRadius / 2.0;

            // Baseline or Marker Number
            if (BaseLine == 0)
            {
                // Add thicker baseline
                double x1 = rectX - strokeCorrection;
                double x2 = rectX + rectWidth + strokeCorrection;
                double y  = rectY - strokeCorrection;

                sb.AppendFormat(LINE,
                                chordOptions.StrokeWidth * 2.0,
                                x1,
                                y,
                                x2,
                                y);
            }
            else if (BaseLine > 1)
            {
                // Add marker number
                double nFontSize = hSpacing * 0.75;

                double nX = rectX + rectWidth + (chordOptions.Margin / 4.0);
                double nY = rectY - strokeCorrection + ((hSpacing + nFontSize) / 2.0);

                sb.AppendFormat(TEXT,
                                nFontSize,
                                chordOptions.FontFamily,
                                "",
                                "left",
                                nX,
                                nY,
                                BaseLine);
            }

            // Marks

            int firstMark = -1;
            int lastMark  = -1;

            bool onBarre = false;

            for (int mark = 0; mark < Marks.Length; mark++)
            {
                double mX = rectX + (vSpacing * mark);
                double mY = rectY + (hSpacing / 2.0) + (hSpacing * (Marks[mark] - 1));

                if (Marks[mark] > 0 && Marks[mark] <= NumFrets) // Mark
                {
                    if (!onBarre)
                    {
                        firstMark = mark;
                        onBarre   = true;
                    }

                    if (onBarre)
                    {
                        if (Marks[firstMark] > Marks[mark])
                        {
                            firstMark = mark;
                        }
                        lastMark = mark;
                    }

                    sb.AppendFormat(SOLID_CIRCLE,
                                    markRadius,
                                    mX,
                                    mY);
                }
                else
                {
                    onBarre = false;               // Hit an unmarked string, restart the barre

                    mY = rectY - (hSpacing / 2.0); // Align above top line

                    if (Marks[mark] == 0)          // Open string
                    {
                        if (chordOptions.OpenStringType == OpenStringType.Circle)
                        {
                            sb.AppendFormat(OPEN_CIRCLE,
                                            chordOptions.StrokeWidth,
                                            muteRadius,
                                            mX,
                                            mY);
                        }
                    }
                    else if (Marks[mark] < 0) // Muted string
                    {
                        sb.AppendFormat(LINE,
                                        chordOptions.StrokeWidth,
                                        mX - muteRadius,  // top left
                                        mY - muteRadius,  // top left
                                        mX + muteRadius,  // bottom right
                                        mY + muteRadius); // bottom right

                        sb.AppendFormat(LINE,
                                        chordOptions.StrokeWidth,
                                        mX - muteRadius,  // bottom left
                                        mY + muteRadius,  // bottom left
                                        mX + muteRadius,  // top right
                                        mY - muteRadius); // top right
                    }
                }
            }

            // Barre
            int barreFret = Barre;

            if (barreFret < 0) // Calculate auto-barre
            {
                if (firstMark >= 0 && lastMark >= 0 && firstMark != lastMark)
                {
                    barreFret = Math.Min(Marks[firstMark], Marks[lastMark]);
                }
                else
                {
                    barreFret = 0;
                }
            }

            if (barreFret != 0 && barreFret <= NumFrets)
            {
                double bStartX = rectX + (chordOptions.FullBarres ? 0 : (firstMark * vSpacing));
                double bEndX   = rectX + (chordOptions.FullBarres ? rectWidth : (lastMark * vSpacing));

                double bY = rectY + (hSpacing / 2.0) + (hSpacing * (barreFret - 1));

                if (chordOptions.BarreType == BarreType.Arc)
                {
                    double bRadiusX = rectWidth;
                    double bRadiusY = hSpacing;

                    sb.AppendFormat(ARC,
                                    chordOptions.StrokeWidth,
                                    bStartX,
                                    bY,
                                    bRadiusX,
                                    bRadiusY,
                                    bEndX,
                                    bY);
                }
                else if (chordOptions.BarreType == BarreType.Straight)
                {
                    sb.AppendFormat(LINE,
                                    chordOptions.StrokeWidth,
                                    bStartX,
                                    bY,
                                    bEndX,
                                    bY);
                }
            }

            return(String.Format(SVG,
                                 chordOptions.Width,
                                 chordOptions.Height,
                                 sb.ToString().Trim()));
        }