@@ -629,148 +629,6 @@ private void CheckPlaybackStop(
629
629
CompareReceivedEvents ( playedEvents , expectedPlayedEvents . ToList ( ) ) ;
630
630
}
631
631
632
- private void CheckDataTracking (
633
- Action < Playback > setupTracking ,
634
- ICollection < EventToSend > eventsToSend ,
635
- ICollection < EventToSend > eventsWillBeSent ,
636
- TimeSpan moveFrom ,
637
- TimeSpan moveTo ,
638
- bool useOutputDevice ,
639
- TimeSpan ? afterMovePause = null ,
640
- Action < Playback > afterMovePlaybackAction = null )
641
- {
642
- if ( useOutputDevice )
643
- CheckDataTrackingWithOutputDevice ( setupTracking , eventsToSend , eventsWillBeSent , moveFrom , moveTo , afterMovePause , afterMovePlaybackAction ) ;
644
- else
645
- CheckDataTrackingWithoutOutputDevice ( setupTracking , eventsToSend , eventsWillBeSent , moveFrom , moveTo , afterMovePause , afterMovePlaybackAction ) ;
646
- }
647
-
648
- private void CheckDataTrackingWithOutputDevice (
649
- Action < Playback > setupTracking ,
650
- ICollection < EventToSend > eventsToSend ,
651
- ICollection < EventToSend > eventsWillBeSent ,
652
- TimeSpan moveFrom ,
653
- TimeSpan moveTo ,
654
- TimeSpan ? afterMovePause = null ,
655
- Action < Playback > afterMovePlaybackAction = null )
656
- {
657
- var playbackContext = new PlaybackContext ( ) ;
658
-
659
- var receivedEvents = playbackContext . ReceivedEvents ;
660
- var sentEvents = playbackContext . SentEvents ;
661
- var stopwatch = playbackContext . Stopwatch ;
662
- var tempoMap = playbackContext . TempoMap ;
663
-
664
- var eventsForPlayback = GetEventsForPlayback ( eventsToSend , tempoMap ) ;
665
- var notes = eventsForPlayback . GetNotes ( ) . ToArray ( ) ;
666
-
667
- using ( var outputDevice = OutputDevice . GetByName ( SendReceiveUtilities . DeviceToTestOnName ) )
668
- {
669
- SendReceiveUtilities . WarmUpDevice ( outputDevice ) ;
670
- outputDevice . EventSent += ( _ , e ) => sentEvents . Add ( new SentEvent ( e . Event , stopwatch . Elapsed ) ) ;
671
-
672
- using ( var playback = eventsForPlayback . GetPlayback ( tempoMap , outputDevice ) )
673
- {
674
- setupTracking ( playback ) ;
675
-
676
- using ( var inputDevice = InputDevice . GetByName ( SendReceiveUtilities . DeviceToTestOnName ) )
677
- {
678
- inputDevice . EventReceived += ( _ , e ) =>
679
- {
680
- lock ( playbackContext . ReceivedEventsLockObject )
681
- {
682
- receivedEvents . Add ( new ReceivedEvent ( e . Event , stopwatch . Elapsed ) ) ;
683
- }
684
- } ;
685
- inputDevice . StartEventsListening ( ) ;
686
- stopwatch . Start ( ) ;
687
- playback . Start ( ) ;
688
-
689
- WaitOperations . Wait ( ( ) => stopwatch . Elapsed >= moveFrom ) ;
690
- playback . MoveToTime ( ( MetricTimeSpan ) moveTo ) ;
691
-
692
- if ( afterMovePause != null )
693
- {
694
- var currentElapsed = stopwatch . Elapsed ;
695
- WaitOperations . Wait ( ( ) => stopwatch . Elapsed >= currentElapsed + afterMovePause ) ;
696
-
697
- afterMovePlaybackAction ( playback ) ;
698
- }
699
-
700
- var timeout = TimeSpan . FromTicks ( eventsWillBeSent . Sum ( e => e . Delay . Ticks ) ) + SendReceiveUtilities . MaximumEventSendReceiveDelay ;
701
- var areEventsReceived = WaitOperations . Wait ( ( ) => receivedEvents . Count == eventsWillBeSent . Count , timeout ) ;
702
- Assert . IsTrue ( areEventsReceived , $ "Events are not received for timeout { timeout } .") ;
703
-
704
- stopwatch . Stop ( ) ;
705
-
706
- var playbackStopped = WaitOperations . Wait ( ( ) => ! playback . IsRunning , SendReceiveUtilities . MaximumEventSendReceiveDelay ) ;
707
- Assert . IsTrue ( playbackStopped , "Playback is running after completed." ) ;
708
- }
709
- }
710
- }
711
-
712
- CompareSentReceivedEvents ( sentEvents , receivedEvents , eventsWillBeSent . ToList ( ) ) ;
713
- }
714
-
715
- private void CheckDataTrackingWithoutOutputDevice (
716
- Action < Playback > setupTracking ,
717
- ICollection < EventToSend > eventsToSend ,
718
- ICollection < EventToSend > eventsWillBeSent ,
719
- TimeSpan moveFrom ,
720
- TimeSpan moveTo ,
721
- TimeSpan ? afterMovePause = null ,
722
- Action < Playback > afterMovePlaybackAction = null )
723
- {
724
- var playbackContext = new PlaybackContext ( ) ;
725
-
726
- var receivedEvents = playbackContext . ReceivedEvents ;
727
- var sentEvents = playbackContext . SentEvents ;
728
- var stopwatch = playbackContext . Stopwatch ;
729
- var tempoMap = playbackContext . TempoMap ;
730
-
731
- var eventsForPlayback = GetEventsForPlayback ( eventsToSend , tempoMap ) ;
732
- var notes = eventsForPlayback . GetNotes ( ) . ToArray ( ) ;
733
-
734
- using ( var playback = eventsForPlayback . GetPlayback ( tempoMap ) )
735
- {
736
- setupTracking ( playback ) ;
737
-
738
- playback . EventPlayed += ( _ , e ) =>
739
- {
740
- lock ( playbackContext . ReceivedEventsLockObject )
741
- {
742
- receivedEvents . Add ( new ReceivedEvent ( e . Event , stopwatch . Elapsed ) ) ;
743
- sentEvents . Add ( new SentEvent ( e . Event , stopwatch . Elapsed ) ) ;
744
- }
745
- } ;
746
-
747
- stopwatch . Start ( ) ;
748
- playback . Start ( ) ;
749
-
750
- WaitOperations . Wait ( ( ) => stopwatch . Elapsed >= moveFrom ) ;
751
- playback . MoveToTime ( ( MetricTimeSpan ) moveTo ) ;
752
-
753
- if ( afterMovePause != null )
754
- {
755
- var currentElapsed = stopwatch . Elapsed ;
756
- WaitOperations . Wait ( ( ) => stopwatch . Elapsed >= currentElapsed + afterMovePause ) ;
757
-
758
- afterMovePlaybackAction ( playback ) ;
759
- }
760
-
761
- var timeout = TimeSpan . FromTicks ( eventsWillBeSent . Sum ( e => e . Delay . Ticks ) ) + SendReceiveUtilities . MaximumEventSendReceiveDelay ;
762
- var areEventsReceived = WaitOperations . Wait ( ( ) => receivedEvents . Count == eventsWillBeSent . Count , timeout ) ;
763
- Assert . IsTrue ( areEventsReceived , $ "Events are not received for timeout { timeout } .") ;
764
-
765
- stopwatch . Stop ( ) ;
766
-
767
- var playbackStopped = WaitOperations . Wait ( ( ) => ! playback . IsRunning , SendReceiveUtilities . MaximumEventSendReceiveDelay ) ;
768
- Assert . IsTrue ( playbackStopped , "Playback is running after completed." ) ;
769
- }
770
-
771
- CompareSentReceivedEvents ( sentEvents , receivedEvents , eventsWillBeSent . ToList ( ) ) ;
772
- }
773
-
774
632
private static IEnumerable < MidiEvent > GetEventsForPlayback ( IEnumerable < EventToSend > eventsToSend , TempoMap tempoMap )
775
633
{
776
634
var eventsForPlayback = new List < MidiEvent > ( ) ;
0 commit comments