Ejemplo n.º 1
0
        public PatternRow AddPatternIfRequired(X0xPattern x0xPattern, ushort tempo)
        {
            var bytes       = x0xPattern.ToByteArray();
            var bytesstring = bytes.ToByteString();

            if (_patternDictionary.TryGetValue(bytesstring, out Guid patternGuid))
            {
                return(Pattern.FindByPatternId(patternGuid));
            }

            // Add the pattern
            var pattern = Pattern.AddPatternRow(Guid.NewGuid(), x0xPattern.Name, x0xPattern.Length, "x0xb0x", tempo, bytes, string.Empty);

            _patternDictionary.Add(bytesstring, pattern.PatternId);

            // Add the steps
            byte lastNoteValue = X0xStep.X0xC2;
            byte stepNumber    = 0;

            foreach (var step in x0xPattern.Steps)
            {
                if (step.IsEndOfPattern)
                {
                    break;
                }

                byte noteValue;
                if (step.IsRest)
                {
                    noteValue = lastNoteValue;
                }
                else
                {
                    noteValue     = step.NoteValue;
                    lastNoteValue = noteValue;
                }

                Step.AddStepRow(pattern, stepNumber++, noteValue, !step.IsRest, step.HasAccent, step.HasSlide);
            }

            // Set the pattern length
            pattern.Length = stepNumber;

            return(pattern);
        }