private static int GetUpCount(int lowNote)
        {
            var noteName = NoteHelper.NumberToNote(lowNote);

            if (noteName == "B2" || noteName == "C3")
            {
                return(0);
            }

            return(35 - lowNote);
        }
        private void LoadTrainingData(List <Phrase> sourceRiffs = null)
        {
            if (sourceRiffs == null)
            {
                _riffs = Directory.GetFiles(_rootFolder, "*.mid", SearchOption.AllDirectories)
                         .Select(x => MidiHelper.ReadMidi(x).Phrases[0])
                         .ToList();
            }
            else
            {
                _riffs = sourceRiffs.ToList();
            }



            var largeRiffs = _riffs.Where(riff => riff.PhraseLength > _riffLength).ToList();

            foreach (var largeRiff in largeRiffs)
            {
                PhraseHelper.TrimPhrase(largeRiff, _riffLength);
            }

            foreach (var halfSizeRiff in _riffs.Where(riff => riff.PhraseLength == _riffLength / 2M))
            {
                PhraseHelper.DuplicatePhrase(halfSizeRiff);
            }

            foreach (var quarterSizeRiff in _riffs.Where(riff => riff.PhraseLength == _riffLength / 4M))
            {
                PhraseHelper.DuplicatePhrase(quarterSizeRiff);
                PhraseHelper.DuplicatePhrase(quarterSizeRiff);
            }

            foreach (var wrongSizeRiff in _riffs.Where(riff => riff.PhraseLength != _riffLength))
            {
                Console.WriteLine("Riff " + wrongSizeRiff.Description + " is not " + _riffLength + " steps long - it's " + wrongSizeRiff.PhraseLength);
            }

            _riffs = _riffs.Where(riff => riff.PhraseLength == _riffLength).ToList();

            var wrongScaleRiffs = new List <Phrase>();

            foreach (var scaleRiff in _riffs)
            {
                var matchingScales = ScaleHelper.FindMatchingScales(scaleRiff).Where(x => x.DistanceFromScale == 0).Select(x => x.Scale.Name).ToList();
                if (!matchingScales.Contains(_baseScale))
                {
                    Console.WriteLine("Riff " + scaleRiff.Description + " DOES NOT contain base scale - is possibly " + (matchingScales.FirstOrDefault() ?? "??"));
                    wrongScaleRiffs.Add(scaleRiff);
                }
            }
            _riffs = _riffs.Except(wrongScaleRiffs).ToList();


            var wrongOctaveRiffs = new List <Phrase>();
            var lowestNote       = NoteHelper.NoteToNumber("C2");
            var highestNote      = NoteHelper.NoteToNumber("C4");

            foreach (var octaveRiff in _riffs)
            {
                var lowNote  = octaveRiff.Elements.Min(x => x.Note);
                var highNote = octaveRiff.Elements.Max(x => x.Note);

                if (lowNote >= NoteHelper.NoteToNumber("C3") && lowNote < NoteHelper.NoteToNumber("C4"))
                {
                    NoteHelper.ShiftNotesDirect(octaveRiff, 1, Interval.Octave, Direction.Down);
                    lowNote  = octaveRiff.Elements.Min(x => x.Note);
                    highNote = octaveRiff.Elements.Max(x => x.Note);
                }
                if (lowNote >= NoteHelper.NoteToNumber("C1") && lowNote < NoteHelper.NoteToNumber("C2"))
                {
                    NoteHelper.ShiftNotesDirect(octaveRiff, 1, Interval.Octave, Direction.Up);
                    lowNote  = octaveRiff.Elements.Min(x => x.Note);
                    highNote = octaveRiff.Elements.Max(x => x.Note);
                }

                if (lowNote < lowestNote || highNote > highestNote)
                {
                    Console.WriteLine("Riff "
                                      + octaveRiff.Description
                                      + " (" + NoteHelper.NumberToNote(lowNote)
                                      + "-" + NoteHelper.NumberToNote(highNote)
                                      + ") is outside the correct note range ("
                                      + NoteHelper.NumberToNote(lowestNote)
                                      + "-" + NoteHelper.NumberToNote(highestNote)
                                      + ").");
                    wrongOctaveRiffs.Add(octaveRiff);
                }
            }
            _riffs = _riffs.Except(wrongOctaveRiffs).ToList();
        }