/// <summary> Checks that a fg has at most one active musical loop </summary> /// <returns> true if one or fewer active loops, false otherwise</returns> public bool CheckMaxOneActiveFGLoop(LoopFunctionalGroup fg) { int activeLoops = 0; int key = fg.GetHashCode(); List <MusicalLoop> fgList; // Given fg as key, calculate number of active loops in its list of musical loops if (loopsByFGGroup.TryGetValue(key, out fgList)) { foreach (MusicalLoop loop in fgList) { if (loop.GetLoopState() != LoopState.Inactive && loop.GetLoopState() != LoopState.Syncing) { activeLoops++; } } if (activeLoops > 1) { return(false); } } else { Console.WriteLine("ERROR: FG Group not found in LoopFGHashMap!"); return(false); } return(true); }
/// <summary> MusicalLoop Constructor </summary> /// <exception cref="ArgumentNullException"> Thrown if input material, particle system, or LoopFGHashMap are null </exception> /// <exception cref="MultipleActiveLoopsInFGException"> Thrown if fg has multiple active loops </exception> public MusicalLoop(LoopFunctionalGroup fg1, string soundFile1, Material mat1, uint currMeasure, ParticleSystem particleSystem1, LoopFGHashMap lFGHashMap1) { // Pre-conditions if (mat1 == null) { throw new ArgumentNullException(String.Format("{0} is null", mat1), "mat1"); } if (particleSystem1 == null) { throw new ArgumentNullException(String.Format("{0} is null", particleSystem1), "particleSystem1"); } if (lFGHashMap1 == null) { throw new ArgumentNullException(String.Format("{0} is null", lFGHashMap1), "lFGHashMap1"); } if (!lFGHashMap1.CheckMaxOneActiveFGLoop(fg1)) { throw new MultipleActiveLoopsInFGException(fg1.ToString()); } // Initialize variables this.funcGroup = fg1; this.soundFile = soundFile1; this.mat = mat1; this.particleSystem = particleSystem1; this.lFGHashMap = lFGHashMap1; SetLoopState(LoopState.Inactive, currMeasure); }
/// <summary> /// Initializes a match's loop, and adds it to the loopPerFGHashMap /// </summary> private void InitializeMusicalLoops() { Material mat = new Material(Color.FromName("Black")); string soundfile = "bass.png"; LoopFunctionalGroup fg = LoopFunctionalGroup.Percussion; //Fill the loops array with musical loops for (int i = 0; i < loops.Length; i++) { MusicalLoop loop = new MusicalLoop(fg, soundfile, mat, measure, pSystem, lFGHashMap); loops[i] = loop; lFGHashMap.Add(loop); newMeasureHandler.NewMeasure += loop.OnNewMeasureEvent; } }