/// <summary> /// Waiting state. /// </summary> /// <param name="e"> /// Information about the event. /// </param> private void Waiting(SysRealtimeEventArgs e) { // If this is a clock event. if (e.Message.Type == SysRealtimeType.Clock) { // Keep track of time stamp. prevTimeStamp = e.TimeStamp; if (MasterEnabled) { midiSender.Send(e.Message); } // The first clock message has been received, start the tick // generator. tickGenerator.Start(); // Transition to the running state. state = new SlaveModeCallback(Running); } // Else if this is a stop event. else if (e.Message.Type == SysRealtimeType.Stop) { if (MasterEnabled) { midiSender.Send(e.Message); } // Transition to the initial state. state = new SlaveModeCallback(Initial); // Raise the stopping event. OnStopping(); } }
/// <summary> /// Initial state. /// </summary> /// <param name="e"> /// Information about the event. /// </param> private void Initial(SysRealtimeEventArgs e) { // If this is a start event. if (e.Message.Type == SysRealtimeType.Start) { if (MasterEnabled) { midiSender.Send(e.Message); } // Transition to the waiting state. state = new SlaveModeCallback(Waiting); // Raise starting event. OnStarting(); } // Else if this is a continue event. else if (e.Message.Type == SysRealtimeType.Continue) { // Transition to the waiting state. state = new SlaveModeCallback(Waiting); // Raise contining event. OnContinuing(); } }
/// <summary> /// Running state. /// </summary> /// <param name="e"> /// Information about the event. /// </param> private void Running(SysRealtimeEventArgs e) { // If this is a clock event. if (e.Message.Type == SysRealtimeType.Clock) { // Calculate tempo based on the time that has elapsed since the // last clock message. // // To calculate the tempo based on clock messages, determine // the time in milliseconds that have elapsed since the last // clock message. Since there are 24 clock messages per beat, // multiply the elapsed time by 24 to get the milliseconds per // beat value. And since the tempo is measured in microseconds // per beat, multiply this value by 1000. The TempoScale // constant takes care of combining the number of clock // messages per beat with the microsecond scale. int tempo = (e.TimeStamp - prevTimeStamp) * TempoScale; // If the tempo has changed, change the tick generator's tempo. if (tempo != tickGenerator.Tempo && tempo >= TickGenerator.TempoMin && tempo <= TickGenerator.TempoMax) { tickGenerator.Tempo = tempo; } if (MasterEnabled) { midiSender.Send(e.Message); } // Keep track of timestamp. prevTimeStamp = e.TimeStamp; } // Else if this is a stop message. else if (e.Message.Type == SysRealtimeType.Stop) { tickGenerator.Stop(); if (MasterEnabled) { midiSender.Send(e.Message); } // Transition to the initial state. state = new SlaveModeCallback(Initial); // Raise stopping event. OnStopping(); } }
/// <summary> /// Waiting state. /// </summary> /// <param name="e"> /// Information about the event. /// </param> private void Waiting(SysRealtimeEventArgs e) { // If this is a clock event. if(e.Message.Type == SysRealtimeType.Clock) { // Keep track of time stamp. prevTimeStamp = e.TimeStamp; if(MasterEnabled) midiSender.Send(e.Message); // The first clock message has been received, start the tick // generator. tickGenerator.Start(); // Transition to the running state. state = new SlaveModeCallback(Running); } // Else if this is a stop event. else if(e.Message.Type == SysRealtimeType.Stop) { if(MasterEnabled) midiSender.Send(e.Message); // Transition to the initial state. state = new SlaveModeCallback(Initial); // Raise the stopping event. OnStopping(); } }
/// <summary> /// Running state. /// </summary> /// <param name="e"> /// Information about the event. /// </param> private void Running(SysRealtimeEventArgs e) { // If this is a clock event. if(e.Message.Type == SysRealtimeType.Clock) { // Calculate tempo based on the time that has elapsed since the // last clock message. // // To calculate the tempo based on clock messages, determine // the time in milliseconds that have elapsed since the last // clock message. Since there are 24 clock messages per beat, // multiply the elapsed time by 24 to get the milliseconds per // beat value. And since the tempo is measured in microseconds // per beat, multiply this value by 1000. The TempoScale // constant takes care of combining the number of clock // messages per beat with the microsecond scale. int tempo = (e.TimeStamp - prevTimeStamp) * TempoScale; // If the tempo has changed, change the tick generator's tempo. if(tempo != tickGenerator.Tempo && tempo >= TickGenerator.TempoMin && tempo <= TickGenerator.TempoMax) { tickGenerator.Tempo = tempo; } if(MasterEnabled) midiSender.Send(e.Message); // Keep track of timestamp. prevTimeStamp = e.TimeStamp; } // Else if this is a stop message. else if(e.Message.Type == SysRealtimeType.Stop) { tickGenerator.Stop(); if(MasterEnabled) midiSender.Send(e.Message); // Transition to the initial state. state = new SlaveModeCallback(Initial); // Raise stopping event. OnStopping(); } }
/// <summary> /// Initial state. /// </summary> /// <param name="e"> /// Information about the event. /// </param> private void Initial(SysRealtimeEventArgs e) { // If this is a start event. if(e.Message.Type == SysRealtimeType.Start) { if(MasterEnabled) midiSender.Send(e.Message); // Transition to the waiting state. state = new SlaveModeCallback(Waiting); // Raise starting event. OnStarting(); } // Else if this is a continue event. else if(e.Message.Type == SysRealtimeType.Continue) { // Transition to the waiting state. state = new SlaveModeCallback(Waiting); // Raise contining event. OnContinuing(); } }