Ejemplo n.º 1
0
        public IEnumerable <ChordNameMeta> GetTunedChordNames(int[] tuning, bool allMatches = true)
        {
            var ret = new List <ChordNameMeta>();

            var tunedNotes = GetTunedNoteScale(tuning).ToList().Where(x => x != ToneNameEnum.NotSet).ToList();

            if (tunedNotes.Any())
            {
                if (tunedNotes.Count() == 1)
                {
                    var item = new ChordNameMeta();
                    item.ToneName = tunedNotes.Single();
                    ret.Add(item);
                }
                else
                {
                    if (tunedNotes.Count() == 2)
                    {
                        tunedNotes.Add(tunedNotes.First());
                    }
                    if (allMatches)
                    {
                        var items = ChordNameFinder.GetChordNames(tunedNotes);
                        if (items == null)
                        {
                            var item = new ChordNameMeta();
                            item.ToneName = tunedNotes.Single();
                            ret.Add(item);
                        }
                        else
                        {
                            ret.AddRange(items);
                        }
                    }
                    else
                    {
                        var item = ChordNameFinder.GetChordName(tunedNotes);
                        if (item != null)
                        {
                            ret.Add(item);
                        }
                        else
                        {
                            item          = new ChordNameMeta();
                            item.ToneName = tunedNotes.Single();
                            ret.Add(item);
                        }
                    }
                }
            }
            return(ret);
        }
Ejemplo n.º 2
0
        static IEnumerable <ChordNameMeta> EC_CalculateChordSymbols(ECToneNameEnum[] tones, bool firstOnly)
        {
            var ret = new List <ChordNameMeta>();

            if (tones.IsEmpty())
            {
                return(ret);
            }
            var distinctTones = tones.Distinct().OrderBy(x => x.ToInt()).ToList();

            if (distinctTones.Count() == 1)
            {
                ret.Add(new ChordNameMeta()
                {
                    ToneName = ChordNameFinder.GetToneName(distinctTones.First())
                });
                return(ret);
            }
            else if (distinctTones.Count() == 2)
            {
                distinctTones.Add(distinctTones.First());
            }

            var n = distinctTones.Count();

            if (n < 3 || n > 5)
            {
                return(ret);
            }

            var ecNotes = distinctTones.Select(x => EC_NotesDir[((int)x)]).ToArray();

            for (var i = 0; i < EC_Chords.Length; i++)
            {
                for (var j = 0; j < 12; j++)
                {
                    var x = 0;
                    if (n == EC_Chords[i].Notes.Length)
                    {
                        for (var k = 0; k < EC_Chords[i].Notes.Length; k++)
                        {
                            var tone = ((EC_Chords[i].Notes[k] + j - 1) % 12);

                            for (var l = 0; l < n; l++)
                            {
                                if (tone == (int)tones[l])
                                {
                                    x++;
                                }
                            }
                        }
                    }
                    if (x == EC_Chords[i].Notes.Length)
                    {
                        var chord = EC_ShowChord(EC_NotesDir[j] + EC_Chords[i].Description);
                        if (chord != null)
                        {
                            ret.Add(chord);

                            if (firstOnly)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(ret);
        }