Esempio n. 1
0
        /// <summary>
        /// This method setups and plays through the game
        /// First it setups up match
        /// Then it plays through each beat and measure until its reached the end
        /// This method is responsible for handling any exceptions thrown by anything it calls
        /// </summary>
        // <param name="totalBeatsInMatch"> unsigned int that determines how many beats the match will be.</param>
        public void playMatch(uint totalBeatsInMatch)
        {
            Console.WriteLine("Starting match.");

            try {
                InitializeMusicalLoops();
                loops[1].StartSyncing(null, measure, beat);

                //Iterate through each measure until the match is done
                for (measure = 0; (measure * BEATS_PER_MEASURE) + beat < totalBeatsInMatch;)
                {
                    // Start of Measure: Call NewMeasureEvent event
                    if (beat == 0)
                    {
                        NewMeasureEventArgs args = new NewMeasureEventArgs();
                        args.TotalMeasures = measure;
                        newMeasureHandler.OnNewMeasure(args);
                    }

                    //Loop body
                    Console.WriteLine("Beat: " + beat);
                    beat++;

                    //Demonstrates that only one active loop per fg will exist unless programmer error.
                    if (measure == 1 && beat == 2)
                    {
                        loops[0].StartSyncing(loops[1], measure, beat);
                    }

                    //New measure, reset the beat
                    if (beat == 4)
                    {
                        beat = 0;
                        measure++;
                    }
                }
                // Handle exceptions
            } catch (ArgumentException e) {
                Console.WriteLine(e.Message);
                System.Environment.Exit(-1);
            } catch (MultipleActiveLoopsInFGException e) {
                Console.WriteLine(e.Message);
                System.Environment.Exit(-1);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Method called to handle NewMeasureEvent:
        /// - Makes prevLoop Inactive,
        /// - Updates to nextState if necessary
        /// </summary>
        /// <param name="source"> (Object) object which triggered the event </param>
        /// <param name="e"> (NewMeasureEventArgs) arguments associated with event </param>
        public void OnNewMeasureEvent(object source, NewMeasureEventArgs e)
        {
            if (!phasingOut)
            {
                Console.WriteLine("Musical Loop recieved NewMeasureEvent!");
                LoopState lState = GetLoopState();

                if (lState.Name.Equals("Syncing"))
                {
                    if (prevLoop != null)
                    {
                        prevLoop.SetInactive(e.TotalMeasures);
                        prevLoop = null;
                    }
                    particleSystem.PlayQueuedEffects();
                }

                LoopState newState = lState.NewMeasureHandler(e.TotalMeasures, measureOfLastStateChange);
                if (newState != null)
                {
                    SetLoopState(newState, e.TotalMeasures);
                }
            }
        }
        public virtual void OnNewMeasure(NewMeasureEventArgs e)
        {
            EventHandler <NewMeasureEventArgs> handler = NewMeasure;

            handler?.Invoke(this, e);
        }