示例#1
0
        private Note TieNote(ABCNote note)
        {
            var key = note.BaseNote.Type.ToString(System.Globalization.CultureInfo.InvariantCulture) + note.BaseNote.Octave.ToString(System.Globalization.CultureInfo.InvariantCulture);
            int count;

            if (tiedNotes.TryGetValue(key, out count))
            {
                if (count > 0)
                {
                    tiedNotes[key]--;
                    note.BaseNote.Type = 'r';
                    return(note.BaseNote);
                }
            }

            if (IsTiedNote(note.TokenIndex))
            {
                int nextIndex = note.TokenIndex + 1;

                while (nextIndex < tokens.Count)
                {
                    if (IsPlayableNote(tokens[nextIndex]))
                    {
                        Note potential = GetNote(tokens[nextIndex]);
                        if (potential.Type == note.BaseNote.Type && potential.Octave == note.BaseNote.Octave)
                        {
                            if (tiedNotes.ContainsKey(key))
                            {
                                tiedNotes[key]++;
                            }
                            else
                            {
                                tiedNotes[key] = 1;
                            }
                            note.BaseNote.Length += potential.Length;
                            if (!IsTiedNote(nextIndex))
                            {
                                break;
                            }
                        }
                    }

                    nextIndex++;
                }
            }

            return(note.BaseNote);
        }
示例#2
0
        protected virtual Note TieNote(ABCNote note)
        {
            var key = note.BaseNote.Type.ToString(System.Globalization.CultureInfo.InvariantCulture) + note.BaseNote.Octave.ToString(System.Globalization.CultureInfo.InvariantCulture);
            int count;

            if (tiedNotes.TryGetValue(key, out count)) {
                if (count > 0) {
                    tiedNotes[key]--;
                    note.BaseNote.Type = 'r';
                    return note.BaseNote;
                }
            }

            if (IsTiedNote(note.TokenIndex)) {
                int nextIndex = note.TokenIndex + 1;

                while (nextIndex < tokens.Count) {
                    if (IsPlayableNote(tokens[nextIndex])) {
                        Note potential = GetNote(tokens[nextIndex]);
                        if (potential.Type == note.BaseNote.Type && potential.Octave == note.BaseNote.Octave) {
                            if (tiedNotes.ContainsKey(key)) {
                                tiedNotes[key]++;
                            }
                            else {
                                tiedNotes[key] = 1;
                            }
                            note.BaseNote.Length += potential.Length;
                            if (!IsTiedNote(nextIndex)) {
                                break;
                            }
                        }
                    }

                    nextIndex++;
                }
            }

            return note.BaseNote;
        }