Exemple #1
0
        private void ParseHeader(string line)
        {
            Tune tune = tunes[tunes.Count - 1];

            // this does not handle new global information after the first tune properly
            ABCInfo? i = ABCInfo.Parse(line);
            if (i.HasValue) {
                ABCInfo info = i.Value;
                if (info.Identifier == 'T' && strict) {
                    if (tune.Header.Information.Count != 1 || !(tune.Header.Information.Count > 0 && tune.Header.Information.ContainsKey('X')))
                        throw new ABCStrictException("Error reading ABC notation, 'T:title' information field is only allowed after 'X:number' field in strict mode.");
                }

                if (info.Identifier == 'X') {
                    // start new tune
                    tune = new Tune();
                    tunes.Add(tunes.Count, tune);
                }
                else if (info.Identifier == 'K') {
                    // start interpreting notes
                    inTune = true;
                }

                tune.Header.AddInfo(i.Value);
            }
        }
Exemple #2
0
        private void CalculateDuration(Tune tune)
        {
            SetDefaultValues();
            SetHeaderValues();
            SetHeaderValues(selectedTune, true);

            TimeSpan       dur        = TimeSpan.Zero;
            bool           chord      = false;
            List <ABCNote> chordNotes = new List <ABCNote>();

            while (tokenIndex < tokens.Count)
            {
                string token = tokens[tokenIndex];

                char c = token[0];
                if (c == '[' && token == "[")
                {
                    c = '!';
                }

                switch (c)
                {
                case ']':
                    if (chord)
                    {
                        chord = false;
                        var chordLen = GetChord(chordNotes);
                        dur += chordLen;
                    }
                    break;

                case '!':                 // replacement for chord opener
                    chord = true;
                    chordNotes.Clear();
                    break;

                case '|':
                case ':':
                case '[':
                    if (c == '[' && token.EndsWith("]") && token.Length > 2 && token[2] == ':' && token[1] != '|' && token[1] != ':')
                    {
                        InlineInfo(token);
                    }
                    break;

                case 'z':
                case 'Z':
                case 'x':
                    Note rest = GetRest(token);
                    if (!chord)
                    {
                        dur += rest.Length;
                    }
                    else
                    {
                        chordNotes.Add(new ABCNote(rest, tokenIndex));
                    }
                    break;

                case 'a':
                case 'b':
                case 'c':
                case 'd':
                case 'e':
                case 'f':
                case 'g':
                case 'A':
                case 'B':
                case 'C':
                case 'D':
                case 'E':
                case 'F':
                case 'G':
                case '^':
                case '=':
                case '_':
                    Note note = GetNote(token);
                    if (!chord)
                    {
                        dur += note.Length;
                    }
                    else
                    {
                        chordNotes.Add(new ABCNote(note, tokenIndex));
                    }
                    break;
                }

                tokenIndex++;
            }

            tunes[selectedTune].Duration = dur;
        }
Exemple #3
0
        protected virtual void CalculateDuration(Tune tune)
        {
            SetDefaultValues();
            SetHeaderValues();
            SetHeaderValues(selectedTune, true);

            TimeSpan dur = TimeSpan.Zero;
            bool chord = false;
            List<ABCNote> chordNotes = new List<ABCNote>();

            while (tokenIndex < tokens.Count) {
                string token = tokens[tokenIndex];

                char c = token[0];
                if (c == '[' && token == "[")
                    c = '!';

                switch (c) {
                    case ']':
                        if (chord) {
                            chord = false;
                            var chordLen = GetChord(chordNotes);
                            dur += chordLen;
                        }
                        break;
                    case '!': // replacement for chord opener
                        chord = true;
                        chordNotes.Clear();
                        break;
                    case '|':
                    case ':':
                    case '[':
                        if (c == '[' && token.EndsWith("]") && token.Length > 2 && token[2] == ':' && token[1] != '|' && token[1] != ':')
                            InlineInfo(token);
                        break;
                    case 'z':
                    case 'Z':
                    case 'x':
                        Note rest = GetRest(token);
                        if (!chord) {
                            dur += rest.Length;
                        }
                        else {
                            chordNotes.Add(new ABCNote(rest, tokenIndex));
                        }
                        break;
                    case 'a':
                    case 'b':
                    case 'c':
                    case 'd':
                    case 'e':
                    case 'f':
                    case 'g':
                    case 'A':
                    case 'B':
                    case 'C':
                    case 'D':
                    case 'E':
                    case 'F':
                    case 'G':
                    case '^':
                    case '=':
                    case '_':
                        Note note = GetNote(token);
                        if (!chord) {
                            dur += note.Length;
                        }
                        else {
                            chordNotes.Add(new ABCNote(note, tokenIndex));
                        }
                        break;
                }

                tokenIndex++;

                if (dur > settings.MaxDuration) {
                    throw new SongDurationException("Song exceeded maximum duration " + settings.MaxDuration);
                }
            }

            tunes[selectedTune].Duration = dur;
        }