コード例 #1
0
        public static Chord[] Find(Note[] notes, bool strict)
        {
            var results = new List <Chord>();

            foreach (var note in notes)
            {
                foreach (var chordType in Enum.GetValues(typeof(ChordType)).Cast <ChordType>())
                {
                    try
                    {
                        var chord = new Chord(note, chordType);

                        if (chord.Notes.Length == notes.Length &&
                            chord.Notes.All(i => notes.Any(j => i == j ||
                                                           (!strict && Note.Normalize(i) == Note.Normalize(j)))))
                        {
                            results.Add(chord);
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine($"Cannot create chord {note} {chordType}");
                    }
                }
            }

            return(results.OrderBy(i => i.ChordType)
                   .ToArray());
        }
コード例 #2
0
        public static IEnumerable<GuitarChordLayout> Generate(Chord chord, bool allowBarre, bool allowSpecial, bool allowPartial, int maxFret)
        {
            var results = new ConcurrentBag<GuitarChordLayout>();
            var positionsPerString = new HashSet<int>[6];

            //for each string find all positions corresponding to notes from the given chord
            for (var s = 0; s < 6; s++)
            {
                positionsPerString[s] = new HashSet<int>();
                positionsPerString[s].Add(X);

                if (chord.Notes.Any(i => i == _strings[s]))
                {
                    positionsPerString[s].Add(0);
                }
                for (var pos = 1; pos <= maxFret + 3; pos++)
                {
                    var note = _strings[s].NoteAtChromaticDistance(pos);

                    if (chord.Notes.Any(i => Note.Normalize(i) == note))
                    {
                        positionsPerString[s].Add(pos);
                    }
                }
            }

            var layouts = GenerateLayouts(positionsPerString).ToArray();
#if TESTING
            var k = 0;
            layouts = layouts.Skip(k).ToArray();
#endif
            var guitarChordTypes = Enum.GetValues(typeof(GuitarChordType))
                                       .Cast<GuitarChordType>()
                                       .Where(i => (allowSpecial || i != GuitarChordType.Special) &&
                                                   (allowBarre || (i != GuitarChordType.SixStringBarre &&
                                                                   i != GuitarChordType.FiveStringBarre)))
                                       .ToList();
#if !TESTING
            Parallel.ForEach(layouts, layout =>
#else
            foreach(var layout in layouts)
#endif
            {
                foreach (var guitarChordType in guitarChordTypes)
                {
                    var result = new GuitarChordLayout(chord, layout, guitarChordType);
                    var b = result.IsValid(allowPartial) &&
                            result.Fret <= maxFret;
                    if (b)
                    {
                        results.Add(result);
                    }
                }
			}
コード例 #3
0
 public Chord(Note root, ChordType chordType)
 {
     Root      = root;
     ChordType = chordType;
     Intervals = ChordType.ToIntervals();
     Notes     = Intervals.Select(i => Root.NoteAtInterval(i))
                 .ToArray();
     NormalizedNotes = Notes.Select(i => Note.Normalize(i))
                       .ToArray();
     NonMandatoryNotes = ChordType.ToNonMandatoryIntervals()
                         .Select(i => Root.NoteAtInterval(i))
                         .ToArray();
 }