Ejemplo n.º 1
0
        private void AddToSolution(Node TreeNode)
        {
            Node parent = TreeNode;
            string solution = string.Empty;
            while (parent != null)
            {
                foreach (string s in parent.FingerPosition)
                    solution += s + "," + parent.finger + "/";
                parent = parent.Parent;
            }

            for (int i = 0; i < 6; i++)
            {
                if (c[i] == 0 || c[i] == -1)
                    solution += c[i] + "," + i + "/";
            }

            solution = solution.Substring(0, solution.LastIndexOf("/"));

            if (!Solutions.Contains(solution))
            {
                // if rich filter selected
                if (RichCombo.SelectedIndex == 1 && Solutions.Count > 0)
                {
                    // List<string> DeleteList = new List<string>();
                    //for (int i = 0; i < Solutions.Count; i++)
                    //{
                    var a = solution.Split('/').Where(b => !b.Contains("-1")).ToList();
                    //bool IsContained = false;
                    List<string> same = Solutions.Where(c => c.Contains(a[0])).ToList();

                    for (int j = 1; j < a.Count; j++)
                    {
                        same = same.Where(c => c.Split('/').Contains(a[j])).ToList();
                    }

                    //int maxIndex = -1;
                    if (same.Count > 1)
                    {
                        foreach (string s in same)
                        {
                            if (s.Split('/').Where(c => !c.Contains("-1")).Count() < a.Count)
                            {
                                if (!Solutions.Contains(solution)) // To prevent from adding multiple times in foreach
                                {
                                    Solutions.Add(solution);
                                }
                                Solutions.Remove(s);
                            }
                        }

                    }

                    //for (int index = 0; index < same.Count; index++)
                    ////{
                    else if (same.Count == 1)
                    {
                        var selected = same[0].Split('/').Where(b => !b.Contains("-1")).ToList();
                        if (selected.Count < a.Count)
                        {
                            Solutions.Add(solution);
                            Solutions.Remove(same[0]);
                        }
                    }
                    else
                        Solutions.Add(solution);
                    //}
                    // }
                    //foreach (string s in DeleteList)
                    //    Solutions.Remove(s);
                }
                else
                    Solutions.Add(solution);
            }
        }
Ejemplo n.º 2
0
        private void TreeFiltering()
        {
            if (FingerPositions.Count == 0)
                return;

            Solutions.Clear();
            List<int[]> FinalFingering = new List<int[]>();

            for (int i = 0; i < FingerPositions.Count; i++)
            {
                var list = FingerPositions[i].Where(a => a != -1 && a != 0).ToList();
                if (list.Count > 0)
                {
                    var SortedList = list.OrderBy(a => a).ToList();

                    // To filter those fingerings where the distance of first frett and last frett are less and equal to selected distance using ComboBox
                    if ((SortedList[SortedList.Count - 1] - SortedList[0]) <= (Convert.ToInt32(FingerDistanceComboBx.Text) - 1) && (FingerPositions[i].Count(a => a == -1) <= 2))
                        FinalFingering.Add(FingerPositions[i]);
                }
            }

            //=============================================

            string fingerings = string.Empty;
            foreach (int[] c in FinalFingering)
            {
                fingerings += c[0] + "," + c[1] + "," + c[2] + "," + c[3] + "," + c[4] + "," + c[5] + "\t";
            }

            string[] fings = fingerings.Substring(0, fingerings.LastIndexOf('\t')).Split('\t');
            List<string> final = fings.Distinct().ToList();

            for (int j = 0; j < FinalFingering.Count; j++)
            {
                c = FinalFingering[j];

                // Getting min which is not -1 or 0
                int index = 0;
                Min = c.OrderBy(a => a).ToList()[index];

                while (Min <= 0)
                    Min = c.OrderBy(a => a).ToList()[index++];

                Max = c.OrderBy(a => a).ToList()[5];

                int PitchNeedFinger = c.Count(a => a > 0);
                Strings[0] = Strings[1] = Strings[2] = Strings[3] = Strings[4] = Strings[5] = 0;
                int MinCount = c.Count(a => a == Min);

                if (MinCount > 1)   // There are two or more positions on same fret - Using one finger to hold all positions
                {
                    Node root = new Node();
                    root.Parent = null;
                    root.Fret = Min + 1;
                    root.finger = 1;
                    root.FingerPosition = new string[MinCount];
                    int indx = MinCount - 1;

                    for (int i = 5; i >= 0; i--)
                    {
                        if (c[i] == Min)
                        {
                            root.FingerPosition[indx] = c[i] + "," + i.ToString();
                            Strings[i] = 1;
                            indx--;
                        }
                        else if (c[i] == -1 || c[i] == 0)
                            Strings[i] = 1;
                    }

                    bool IsMuteBetweenBarre = false;
                    int MinBarre = Convert.ToInt32(root.FingerPosition[0].Split(',')[1]);
                    int MaxBarre = Convert.ToInt32(root.FingerPosition[root.FingerPosition.Length - 1].Split(',')[1]);

                    for (int i = 5; i >= 0; i--)
                    {
                        if (c[i] == -1 || c[i] == 0)
                        {
                            if (i >= MinBarre && i <= MaxBarre)
                                IsMuteBetweenBarre = true; // Not Good
                        }
                    }

                    if (!IsMuteBetweenBarre)
                        CreateSmallTree(root, 3, PitchNeedFinger - MinCount, 5);
                    else
                    {
                    }
                }

                //===============================================================
                // Changing all variables to their default values because the following is a new tree
                Strings[0] = Strings[1] = Strings[2] = Strings[3] = Strings[4] = Strings[5] = 0;
                Node root2 = new Node();
                root2.Fret = Min;

                for (int i = 5; i >= 0; i--)
                {
                    if (c[i] == -1 || c[i] == 0)
                        Strings[i] = 1;
                }

                for (int i = 5; i >= 0; i--)
                {
                    if (c[i] == Min)
                    {
                        root2.FingerPosition = new string[] { c[i] + "," + i.ToString() };
                        Strings[i] = 1;
                        root2.Parent = null;
                        root2.finger = 1;
                        CreateSmallTree(root2, 3, PitchNeedFinger - 1, i - 1);
                    }
                }
            }

            DrawTab();
        }
Ejemplo n.º 3
0
        private void CreateSmallTree(Node TreeNode, int RemainingFingers, int PitchNeedFinger, int stringNo)
        {
            List<string> positions = new List<string>();
            int fret = TreeNode.Fret;

            while (positions.Count == 0 && fret <= Max)
            {
                for (int i = stringNo; i >= 0; i--)
                {
                    if (c[i] == fret)
                    {
                        positions.Add(c[i] + "," + i.ToString());   // Like x,y in cartesian
                        Node node = new Node();
                        node.Fret = fret;
                        node.finger = TreeNode.finger + 1;
                        node.FingerPosition = new string[] { c[i] + "," + i.ToString() };
                        TreeNode.Children.Add(node);
                        node.Parent = TreeNode;

                        if (((RemainingFingers - 1) >= 0) && (Strings[i] != 1)) // Same string is not held by a finger
                        {
                            Strings[i] = 1;

                            if (PitchNeedFinger - 1 == 0) // Check to see if all pitches has fingers on them
                            {
                                AddToSolution(node);
                                return;
                            }

                            CreateSmallTree(node, RemainingFingers - 1, PitchNeedFinger - 1, i - 1);
                        }
                    }
                }

                if (positions.Count > 1)
                {
                    Node node = new Node();
                    node.Fret = fret + 1;
                    node.finger = TreeNode.finger + 1;
                    node.FingerPosition = new string[positions.Count];
                    for (int i = 0; i < positions.Count; i++)
                        node.FingerPosition[i] = positions[i];

                    ////////////////////////////////////////
                    bool IsMuteBetweenBarre = false;
                    int MaxBarre = Convert.ToInt32(node.FingerPosition[0].Split(',')[1]);
                    int MinBarre = Convert.ToInt32(node.FingerPosition[node.FingerPosition.Length - 1].Split(',')[1]);

                    for (int i = 5; i >= 0; i--)
                    {
                        if (c[i] == -1 || c[i] == 0)
                        {
                            if (i >= MinBarre && i <= MaxBarre)
                                IsMuteBetweenBarre = true; // Not Good
                        }
                    }

                    if (!IsMuteBetweenBarre)
                    {
                        TreeNode.Children.Add(node);
                        node.Parent = TreeNode;

                        if (!CheckBarreIsLegal(positions, fret))
                            return;

                        if ((RemainingFingers - 1) != 0)
                        {
                            if (PitchNeedFinger - 1 == 0) // Check to see if all pitches has fingers on them
                            {
                                AddToSolution(node);
                                return;
                            }

                            CreateSmallTree(node, RemainingFingers - 1, PitchNeedFinger - positions.Count, 5);
                        }
                    }
                }

                fret++;
                stringNo = 5;
            }

            // It needs to check if this is the last node and it gives us the solution
            // Or needs to check if conditions are not satisfied and stop going deep
        }