예제 #1
0
        public Pattern GetPattern()
        {
            Pattern pattern = new Pattern();

            foreach (Chord chord in GetChords())
            {
                pattern.Add(chord);
            }

            if (allSequence != null)
            {
                pattern = ReplacementFormatUtil.ReplaceDollarsWithCandidates(allSequence, GetChords(),
                                                                             new Pattern(GetChords()));
            }

            if (eachSequence != null)
            {
                Pattern p2 = new Pattern();
                foreach (var chordString in pattern.ToString().Split(' '))
                {
                    Chord chord = new Chord(chordString);
                    p2.Add(ReplacementFormatUtil.ReplaceDollarsWithCandidates(eachSequence, chord.GetNotes(), chord));
                }

                pattern = p2;
            }

            return(pattern);
        }
        public void Test_underscores_and_plus()
        {
            var chord = new Chord("Cmaj");

            var result = ReplacementFormatUtil.ReplaceDollarsWithCandidates("$0q+$1q $2h $1h+$2q_$0q", chord.GetNotes(), chord);

            result.ToString().Should().Be("Cq+Eq Gh Eh+Gq_Cq");
        }
        public void Test_replacement_with_chord()
        {
            var chord = new Chord("Cmaj");

            var result = ReplacementFormatUtil.ReplaceDollarsWithCandidates("$0q $1h $2w $!q", chord.GetNotes(), chord);

            result.ToString().Should().Be("Cq Eh Gw CMAJq");
        }
        public void Test_characters_that_dont_get_replaced()
        {
            var patterns = new List <IPatternProducer> {
                new Pattern("C"), null, null
            };

            var result = ReplacementFormatUtil.ReplaceDollarsWithCandidates("$0 T U V", patterns, null);

            result.ToString().Should().Be("C T U V");
        }
        public void Test_replacement_with_individual_appenders()
        {
            var patterns = new List <IPatternProducer>
            {
                new Pattern("C"),
                new Pattern("D"),
                new Pattern("E")
            };

            var result = ReplacementFormatUtil.ReplaceDollarsWithCandidates("$0q $1h $2w $!q", patterns, new Pattern("(C+D+E)"));

            result.ToString().Should().Be("Cq Dh Ew (C+D+E)q");
        }
        public void Test_special_replacement()
        {
            var patterns = new Pattern[3];

            patterns[0] = new Pattern("C");
            var specialMap = new Dictionary <string, IPatternProducer> {
                { "T", new Pattern("E") }
            };

            var result = ReplacementFormatUtil.ReplaceDollarsWithCandidates("$0 T U V $T", patterns, null, specialMap, " ", " ", null);

            result.ToString().Should().Be("C T U V E");
        }
        public void Test_simple_replacement()
        {
            var patterns = new List <IPatternProducer>
            {
                new Pattern("C"),
                new Pattern("D"),
                new Pattern("E"),
            };

            var result =
                ReplacementFormatUtil.ReplaceDollarsWithCandidates("$0 $1 $2 $!", patterns, new Pattern("C+D+E"));

            result.ToString().Should().Be("C D E C+D+E");
        }
        public void Test_replacement_with_long_special_map_keys()
        {
            var chord      = new Chord("Cmaj");
            var specialMap = new Dictionary <string, IPatternProducer>
            {
                ["URANUS"]  = new Pattern("C D E F"),
                ["NEPTUNE"] = new Pattern("A B Ab B"),
                ["JUPITER"] = new Pattern("C G C G"),
                ["MARS"]    = new Pattern("F E D C")
            };

            var result = ReplacementFormatUtil.ReplaceDollarsWithCandidates("$0q,$1h,$2w,$URANUSq,Rq,$NEPTUNEq,$!q", chord.GetNotes(), chord, specialMap, ",", " ", ".");

            result.ToString().Should().Be("Cq. Eh. Gw. Cq. Dq. Eq. Fq. Rq. Aq. Bq. Abq. Bq. CMAJq.");
        }
예제 #9
0
        public Pattern GetPattern()
        {
            string[] intervals = intervalPattern.Split(' ');
            int      counter   = 0;

            Note[] candidateNotes = new Note[intervals.Length];

            foreach (var interval in intervals)
            {
                Note note = new Note((Root.Value + GetHalfsteps(interval)));
                candidateNotes[counter++] = note;
            }
            Pattern intervalNotes = new Pattern(candidateNotes);

            if (AsSequence != null)
            {
                return(ReplacementFormatUtil.ReplaceDollarsWithCandidates(AsSequence, candidateNotes, intervalNotes));
            }
            else
            {
                return(intervalNotes);
            }
        }
예제 #10
0
        public string Preprocess(string musicString, StaccatoParserContext context)
        {
            var retVal = new StringBuilder();

            var splitsville = musicString.Split(' ');

            foreach (string s in splitsville)
            {
                int posColon = 0;
                if ((posColon = s.IndexOf(':')) != -1 && (posColon > 0))
                {
                    string candidateChord = s.Substring(0, posColon);

                    // We don't want to think we have a chord when we really have a key signature or time signature, or
                    // we have a tuplet (indicated by the asterisk)
                    if (Chord.IsValid(candidateChord))
                    {
                        Chord chord = new Chord(candidateChord);

                        // Get the replacement description
                        int    posColon2 = s.FindNextOrEnd(':', posColon + 1);
                        string replacementDescription = s.Substring(posColon + 1, posColon2 - posColon - 1);
                        string dynamics = (posColon2 == s.Length ? "" : s.Substring(posColon2 + 1, s.Length - posColon2 - 1));

                        // If the replacement description starts with a bracket, look up the value in the context's dictionary
                        if (replacementDescription[0] == '[')
                        {
                            var replacementLookup = replacementDescription.Substring(1, replacementDescription.Length - 2);
                            replacementDescription = context.Dictionary[replacementLookup] as string;
                        }

                        var specialReplacers = new Dictionary <string, IPatternProducer>
                        {
                            ["ROOT"]    = chord.Root,
                            ["BASS"]    = chord.GetBassNote(),
                            ["NOTROOT"] = WrapInParens(chord.GetPatternWithNotesExceptRoot())
                        };

                        specialReplacers["NOTBASS"] = WrapInParens(chord.GetPatternWithNotesExceptBass());

                        var result = ReplacementFormatUtil.ReplaceDollarsWithCandidates(
                            replacementDescription,
                            chord.GetNotes(),
                            WrapInParens(chord.GetPatternWithNotes()),
                            specialReplacers,
                            ",",
                            " ",
                            dynamics
                            );
                        retVal.Append(result);
                    }
                    else
                    {
                        retVal.Append(s);
                    }
                }
                else
                {
                    retVal.Append(s);
                }
                retVal.Append(" ");
            }
            return(retVal.ToString().Trim());
        }