コード例 #1
0
        public RelativeVariablesWrapper Handle(string token, string[] tokens, LilyPondStaffAdapter staff, ref int index)
        {
            string tempoValue = tokens[++index];
            staff.AddTempo(tempoValue);

            return null;
        }
コード例 #2
0
        public RelativeVariablesWrapper Handle(string token, string[] tokens, LilyPondStaffAdapter staff, ref int index)
        {
            string timeValue = tokens[++index];

            staff.AddTimeSignature(timeValue);

            return(null);
        }
コード例 #3
0
        public RelativeVariablesWrapper Handle(string token, string[] tokens, LilyPondStaffAdapter staff, ref int index)
        {
            RelativeVariablesWrapper wrapper = new RelativeVariablesWrapper();

            string newRelative = tokens[++index]; //++i -> toevoegen en dan de nieuwe gebruiken, i++ oude gebruiken dan nieuwe toevoegen

            wrapper.relativeStep    = Regex.Match(newRelative, "[a-z]+").Value;
            wrapper.relativeOctave  = DEFAULT_RELATIVE_OCTAVE + (1 * newRelative.Count(x => x == '\''));
            wrapper.relativeOctave -= (1 * newRelative.Count(x => x == ','));

            return(wrapper);
        }
コード例 #4
0
        public RelativeVariablesWrapper Handle(string token, string[] tokens, LilyPondStaffAdapter staff, ref int index)
        {
            string repeatType = tokens[++index];

            switch (repeatType)
            {
            case "volta":
                int repeatCount = int.Parse(tokens[++index]);
                //staff.Symbols.Add(new Repeat { Type = RepeatType.FORWARD });
                break;
            }

            return(null);
        }
コード例 #5
0
        private Score BuildScore(string text)
        {
            Score score = new Score();
            LilyPondStaffAdapter staff = new LilyPondStaffAdapter();

            string[] tokens = text.Split(new string[] { " ", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            // Default relative step is c.
            string relativeStep   = "c";
            int    relativeOctave = DEFAULT_RELATIVE_OCTAVE;

            Dictionary <string, ILilyTokenHandler> lilyTokenHandlers = new Dictionary <string, ILilyTokenHandler>
            {
                { "relative", new RelativeTokenHandler() },
                { "clef", new ClefTokenHandler() },
                { "time", new TimeTokenHandler() },
                { "tempo", new TempoTokenHandler() },
                { "repeat", new RepeatTokenHandler() },
            };

            Dictionary <string, ILilyNonTokenHandler> lilyNonTokenHandlers = new Dictionary <string, ILilyNonTokenHandler>
            {
                { "|", new BarlineHandler() },
                { "{", new NonTokenHandler() },
                { "}", new NonTokenHandler() },
                { "note", new NoteHandler() },
            };

            for (int i = 0; i < tokens.Length; i++)
            {
                string token = tokens[i];
                RelativeVariablesWrapper wrapper;

                if (token.StartsWith("\\")) // tokens
                {
                    string key = token.Substring(1);

                    if (lilyTokenHandlers.ContainsKey(key))
                    {
                        wrapper = lilyTokenHandlers[key].Handle(token, tokens, staff, ref i);
                        if (wrapper != null)
                        {
                            relativeStep   = wrapper.relativeStep;
                            relativeOctave = wrapper.relativeOctave;
                        }
                    }
                    else
                    {
                        return(null); // Invalid token -> error
                    }
                }
                else // Remaining nonTokens
                {
                    if (lilyNonTokenHandlers.ContainsKey(token))   // at this point the token isn't a token anymore tho
                    {
                        lilyNonTokenHandlers[token].Handle(token, staff, null);
                    }
                    else // -> it's not any of the previous we've found -> it's a Note (non)Token. Lets parse it.
                    {
                        wrapper = new RelativeVariablesWrapper();
                        wrapper.relativeStep   = relativeStep;
                        wrapper.relativeOctave = relativeOctave;

                        wrapper = lilyNonTokenHandlers["note"].Handle(token, staff, wrapper);
                        if (wrapper != null)
                        {
                            relativeStep   = wrapper.relativeStep;
                            relativeOctave = wrapper.relativeOctave;
                        }
                        else
                        {
                            return(null); // Invalid note -> error
                        }
                    }
                }
            }

            score.AddStaff(staff);
            return(score);
        }
コード例 #6
0
        public RelativeVariablesWrapper Handle(string token, LilyPondStaffAdapter staff, RelativeVariablesWrapper wrapper)
        {
            staff.Symbols.Add(new Barline());

            return(null);
        }