Exemplo n.º 1
0
        public static bool TryParse(TextEvent textEvent, out DrumMixEvent drumMixEvent)
        {
            drumMixEvent = null;
            if (textEvent.MetaEventType != MetaEventType.TextEvent)
            {
                return(false);
            }

            var match = Regex.Match(textEvent.Text, @"^\[mix (?<difficulty>[0-3]) (?<configuration>.*)\]$");

            if (!match.Success)
            {
                return(false);
            }

            var configuration = match.Groups["configuration"].Value;

            if (!ValidConfigurations.Contains(configuration))
            {
                return(false);
            }

            var difficulty = int.Parse(match.Groups["difficulty"].Value);

            drumMixEvent = new DrumMixEvent(difficulty, configuration, textEvent);
            return(true);
        }
Exemplo n.º 2
0
        public void AddDrumMixEvents(MidiEventCollection midi)
        {
            var drumTrack         = midi.GetTrackByName(TrackName.Drums.ToString());
            var existingMixEvents = drumTrack.
                                    OfType <TextEvent>().
                                    Where(e => e.AbsoluteTime == 0 && e.MetaEventType == MetaEventType.TextEvent).
                                    Select(e => e.AsDrumMixEvent()).
                                    Where(e => e != null).
                                    ToList();

            for (var difficulty = 0; difficulty < 4; difficulty++)
            {
                if (existingMixEvents.Any(e => e.Difficulty == difficulty))
                {
                    continue;
                }

                // Try to keep them in order
                drumTrack.Insert(difficulty + 1, DrumMixEvent.DefaultFor(difficulty));
            }
        }
Exemplo n.º 3
0
        public static DrumMixEvent AsDrumMixEvent(this TextEvent textEvent)
        {
            DrumMixEvent drumMixEvent;

            return(DrumMixEvent.TryParse(textEvent, out drumMixEvent) ? drumMixEvent : null);
        }