示例#1
0
        internal override bool Apply(TablatureContext context, ILogger logger)
        {
            Bar bar;

            if (!this.ToDocumentElement(context, logger, null, out bar))
            {
                return(false);
            }

            if (bar.Rhythm != null && bar.Lyrics != null)
            {
                var beats = bar.Rhythm.Segments.Sum(s => s.FirstVoice.Beats?.Count ?? 0);
                if (beats < bar.Lyrics.Segments.Count)
                {
                    logger.Report(LogLevel.Suggestion, bar.Lyrics.Range, Messages.Suggestion_LyricsTooLong);
                }
            }

            context.AddBar(bar);

            // check if this bar terminates an alternative ending, must be done AFTER adding this bar to context
            if ((bar.CloseLine == CloseBarLine.End || bar.CloseLine == CloseBarLine.EndRepeat) &&
                context.DocumentState.CurrentAlternation != null)
            {
                using (var state = context.AlterDocumentState())
                {
                    state.CurrentAlternation = null;
                }
            }

            return(true);
        }
示例#2
0
        internal override bool Apply(TablatureContext context, ILogger logger)
        {
            var templateBarNodes = this.TemplateBars.Bars;
            var instanceBarNodes = this.InstanceBars.Bars;

            if (instanceBarNodes.Count < templateBarNodes.Count)
            {
                logger.Report(LogLevel.Warning, this.InstanceBars.Range,
                              Messages.Warning_PatternInstanceBarsLessThanTemplateBars);
            }

            var templateBars = new List <Bar>();

            foreach (var barNode in templateBarNodes)
            {
                if (barNode.Lyrics != null)
                {
                    logger.Report(LogLevel.Warning, barNode.Lyrics.Range,
                                  Messages.Warning_TemplateBarCannotContainLyrics);
                }

                Bar bar;
                if (!barNode.ToDocumentElement(context, logger, null, out bar))
                {
                    return(false);
                }

                templateBars.Add(bar);
            }

            var templateIndex = 0;

            foreach (var barNode in instanceBarNodes)
            {
                var templateBar = templateBars[templateIndex];

                Bar instanceBar;
                if (this.ApplyTemplateBar(templateBar, barNode, out instanceBar, context, logger))
                {
                    context.AddBar(instanceBar);
                }

                ++templateIndex;
                if (templateIndex == templateBarNodes.Count)
                {
                    templateIndex = 0;
                }
            }

            return(true);
        }