コード例 #1
0
        private IList <IStringInstrumentNotePosition> stringNotePositionForString(IInstrumentString currentString,
                                                                                  IChord chord, int sti, int typicalFingerSemiToneStretch)
        {
            var ret = new List <IStringInstrumentNotePosition>();

            // TODO : investigate how far should we really accept open strings
            if (sti == 0 && chord.Notes.Any(n => n.Equals(currentString.OpenStringNote)))
            {
                ret.Add(new StringInstrumentNotePosition
                {
                    StringPosition     = currentString.Position,
                    StringNotePosition = 0,
                    Note = currentString.OpenStringNote
                });
            }

            for (int i = sti, j = 0; i < currentString.StringNotes.Count && j < typicalFingerSemiToneStretch; i++, j++)
            {
                var currentNotePosition = currentString.StringNotes[i];
                if (chord.Notes.Any(chordNote => chordNote.Equals(currentNotePosition.Note)))
                {
                    ret.Add(new StringInstrumentNotePosition
                    {
                        Note = currentNotePosition.Note,
                        StringNotePosition = currentNotePosition.Position,
                        StringPosition     = currentString.Position
                    });
                }
            }

            return(ret);
        }
コード例 #2
0
ファイル: Guitar.cs プロジェクト: ScottyMac52/notescaler
        /// <inheritdoc/>
        public int GetNoteInterval(int startString, int startFret, int endString, int endFret, out List <Exception> errorList)
        {
            IInstrumentString startStringRef = null;
            IInstrumentString endStringRef   = null;

            errorList = new List <Exception>();
            if (!Strings.Any(str => str.Number == startString || str.Number == endString))
            {
                if (!Strings.Any(str => str.Number == startString))
                {
                    errorList.Add(new ArgumentException($"There is no string number: {startString}", nameof(GuitarString.Number)));
                }
                if (!Strings.Any(str => str.Number == endString))
                {
                    errorList.Add(new ArgumentException($"There is no string number: {endString}", nameof(GuitarString.Number)));
                }
            }
            else
            {
                startStringRef = Strings.Single(str => str.Number.Equals(startString));
                endStringRef   = Strings.Single(str => str.Number.Equals(endString));
                if (startFret > startStringRef.MaxFret)
                {
                    errorList.Add(new ArgumentException($"Fret: {startFret} doesn't exist on String: {startString}.", nameof(GuitarString.MaxFret)));
                }
                if (endFret > endStringRef.MaxFret)
                {
                    errorList.Add(new ArgumentException($"Fret: {endFret} doesn't exist on String: {endString}.", nameof(GuitarString.MaxFret)));
                }
            }
            if (errorList.Count() == 0)
            {
                var startNote = startStringRef.GetNote(startFret);
                var endNote   = endStringRef.GetNote(endFret);
                return(GetNoteInterval(startNote, endNote));
            }
            else
            {
                return(0);
            }
        }