示例#1
0
        /// <summary>
        /// Retrieves the current composition context.
        /// </summary>
        /// <returns></returns>
        public CompositionContext GetCurrentCompositionContext()
        {
            if (_notePairs.Count > 1)
            {
                return(_compositionContexts.GetSpecificContext(
                           _factory.CreateCompositionContext(
                               _notePairs[_notePairs.Count - 2],
                               _notePairs[_notePairs.Count - 1]
                               )
                           ));
            }

            return(_compositionContexts.GetSpecificContext(
                       _factory.CreateCompositionContext(
                           NoteMotion.Descending,
                           NoteMotionSpan.Step,
                           ScaleDegree.Root,
                           NoteMotion.Descending,
                           NoteMotionSpan.Step,
                           ScaleDegree.Root
                           )
                       ));
        }
示例#2
0
        /// <summary>
        /// Minimizes the roll space for the given CompositionContext and detrimental NoteChoice to help prevent choosing
        /// that detrimental note again.
        /// </summary>
        /// <param name="context">The CompositionContext which led to the NoteChoice being chosen</param>
        /// <param name="noteChoice">The detrimental NoteChoice</param>
        public void MinimizeDetrimentalNoteChoiceWeight(CompositionContext context, NoteChoice noteChoice)
        {
            var specificContext = _compositionContexts.GetSpecificContext(context);
            var noteChoiceWeightsNoteChoices = StrategyDictionary[specificContext];

            var foundNoteChoiceWeightNoteChoice =
                noteChoiceWeightsNoteChoices.FirstOrDefault(
                    noteWeightNoteChoice => noteWeightNoteChoice.NoteChoice.Equals(noteChoice)
                    );

            var index = noteChoiceWeightsNoteChoices.IndexOf(foundNoteChoiceWeightNoteChoice);

            switch (index)
            {
            case -1:
                return;

            case 0:
                var firstNoteChoiceWeightNoteChoice  = noteChoiceWeightsNoteChoices[0];
                var secondNoteChoiceWeightNoteChoice = noteChoiceWeightsNoteChoices[1];

                firstNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight        = AdjustedNoteChoiceWeightValue;
                firstNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling = AdjustedNoteChoiceWeightValue;

                secondNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor =
                    firstNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight + 1;
                secondNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight =
                    secondNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling -
                    secondNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor;
                break;

            default:
                if (index == noteChoiceWeightsNoteChoices.Count - 1)
                {
                    var lastNoteChoiceWeightNoteChoice =
                        noteChoiceWeightsNoteChoices[noteChoiceWeightsNoteChoices.Count - 1];
                    var secondToLastNoteChoiceWeightNoteChoice =
                        noteChoiceWeightsNoteChoices[noteChoiceWeightsNoteChoices.Count - 2];

                    lastNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight      = AdjustedNoteChoiceWeightValue;
                    lastNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor =
                        _noteChoiceWeightGenerator.GetNoteChoiceWeightCeiling(noteChoiceWeightsNoteChoices.Count) -
                        lastNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight;

                    secondToLastNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling =
                        lastNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor - 1;
                    secondToLastNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight =
                        secondToLastNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling -
                        secondToLastNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor;
                }
                else
                {
                    var noteChoiceWeightNoteChoice     = noteChoiceWeightsNoteChoices[index];
                    var nextNoteChoiceWeightNoteChoice = noteChoiceWeightsNoteChoices[index + 1];

                    noteChoiceWeightNoteChoice.NoteChoiceWeight.Weight        = AdjustedNoteChoiceWeightValue;
                    noteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling =
                        noteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor +
                        noteChoiceWeightNoteChoice.NoteChoiceWeight.Weight;

                    nextNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor =
                        noteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling + 1;
                    nextNoteChoiceWeightNoteChoice.NoteChoiceWeight.Weight =
                        nextNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightCeiling -
                        nextNoteChoiceWeightNoteChoice.NoteChoiceWeight.WeightFloor;
                }

                break;
            }
        }