From 3f5d5fc001b37da41f8262ed5c20ce2105d4c7ed Mon Sep 17 00:00:00 2001 From: Flamefire Date: Fri, 14 Mar 2014 00:50:13 +0100 Subject: [PATCH] Move CDelayTest to a file in Lib/Sound --- Vocaluxe/Lib/Sound/CDelayTest.cs | 102 +++++++++++++++++++++++ Vocaluxe/Screens/CScreenOptionsRecord.cs | 98 ---------------------- Vocaluxe/Vocaluxe.csproj | 1 + 3 files changed, 103 insertions(+), 98 deletions(-) create mode 100644 Vocaluxe/Lib/Sound/CDelayTest.cs diff --git a/Vocaluxe/Lib/Sound/CDelayTest.cs b/Vocaluxe/Lib/Sound/CDelayTest.cs new file mode 100644 index 00000000..047b3999 --- /dev/null +++ b/Vocaluxe/Lib/Sound/CDelayTest.cs @@ -0,0 +1,102 @@ +using System.Diagnostics; +using Vocaluxe.Base; + +namespace Vocaluxe.Lib.Sound +{ + class CDelayTest + { + private struct SDelayChannel + { + public int Channel; + public bool Finished; + } + + private const float _MaxDelayTime = 1000; + public bool Running { get; private set; } + private readonly Stopwatch _Timer = new Stopwatch(); + private int _Stream = -1; + + private readonly SDelayChannel[] _DelaysChannel; + public readonly int[] Delays; + public readonly int NumChannels; + + public CDelayTest(int numChannels) + { + NumChannels = numChannels; + _DelaysChannel = new SDelayChannel[NumChannels]; + Delays = new int[NumChannels]; + } + + public void Start(int[] channels) + { + if (Running) + return; + Reset(); + for (int i = 0; i < _DelaysChannel.Length; i++) + { + if (i < channels.Length) + { + _DelaysChannel[i].Finished = false; + _DelaysChannel[i].Channel = channels[i]; + } + else + _DelaysChannel[i].Finished = true; + } + _Stream = CSound.PlaySound(ESounds.T440, false); + Running = true; + } + + public void Reset() + { + Running = false; + for (int i = 0; i < _DelaysChannel.Length; i++) + Delays[i] = 0; + _CloseStream(); + } + + private void _CloseStream() + { + if (_Stream != -1) + { + CSound.Close(_Stream); + _Stream = -1; + } + } + + public void Update() + { + if (!Running) + return; + if (!_Timer.IsRunning) + { + if (CSound.GetPosition(_Stream) > 0f) + _Timer.Restart(); + } + if (!_Timer.IsRunning) + return; + + bool isActive = false; + if (_Timer.ElapsedMilliseconds <= _MaxDelayTime) + { + for (int i = 0; i < _DelaysChannel.Length; i++) + { + if (_DelaysChannel[i].Channel < 0 || _DelaysChannel[i].Finished) + continue; + if (CSound.RecordGetMaxVolume(_DelaysChannel[i].Channel) > 0.1f && CSound.RecordGetTone(_DelaysChannel[i].Channel) == 9) + { + Delays[i] = (int)_Timer.ElapsedMilliseconds; + _DelaysChannel[i].Finished = true; + } + else + isActive = true; + } + } + if (!isActive) + { + Running = false; + _CloseStream(); + _Timer.Stop(); + } + } + } +} \ No newline at end of file diff --git a/Vocaluxe/Screens/CScreenOptionsRecord.cs b/Vocaluxe/Screens/CScreenOptionsRecord.cs index 5a35d6b6..979809c6 100644 --- a/Vocaluxe/Screens/CScreenOptionsRecord.cs +++ b/Vocaluxe/Screens/CScreenOptionsRecord.cs @@ -17,7 +17,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Diagnostics; using System.Windows.Forms; using Vocaluxe.Base; using Vocaluxe.Lib.Sound; @@ -26,103 +25,6 @@ using VocaluxeLib.Menu; namespace Vocaluxe.Screens { - class CDelayTest - { - private struct SDelayChannel - { - public int Channel; - public bool Finished; - } - - private const float _MaxDelayTime = 1000; - public bool Running { get; private set; } - private readonly Stopwatch _Timer = new Stopwatch(); - private int _Stream = -1; - - private readonly SDelayChannel[] _DelaysChannel; - public readonly int[] Delays; - public readonly int NumChannels; - - public CDelayTest(int numChannels) - { - NumChannels = numChannels; - _DelaysChannel = new SDelayChannel[NumChannels]; - Delays = new int[NumChannels]; - } - - public void Start(int[] channels) - { - if (Running) - return; - Reset(); - for (int i = 0; i < _DelaysChannel.Length; i++) - { - if (i < channels.Length) - { - _DelaysChannel[i].Finished = false; - _DelaysChannel[i].Channel = channels[i]; - } - else - _DelaysChannel[i].Finished = true; - } - _Stream = CSound.PlaySound(ESounds.T440, false); - Running = true; - } - - public void Reset() - { - Running = false; - for (int i = 0; i < _DelaysChannel.Length; i++) - Delays[i] = 0; - _CloseStream(); - } - - private void _CloseStream() - { - if (_Stream != -1) - { - CSound.Close(_Stream); - _Stream = -1; - } - } - - public void Update() - { - if (!Running) - return; - if (!_Timer.IsRunning) - { - if (CSound.GetPosition(_Stream) > 0f) - _Timer.Restart(); - } - if (!_Timer.IsRunning) - return; - - bool isActive = false; - if (_Timer.ElapsedMilliseconds <= _MaxDelayTime) - { - for (int i = 0; i < _DelaysChannel.Length; i++) - { - if (_DelaysChannel[i].Channel < 0 || _DelaysChannel[i].Finished) - continue; - if (CSound.RecordGetMaxVolume(_DelaysChannel[i].Channel) > 0.1f && CSound.RecordGetTone(_DelaysChannel[i].Channel) == 9) - { - Delays[i] = (int)_Timer.ElapsedMilliseconds; - _DelaysChannel[i].Finished = true; - } - else - isActive = true; - } - } - if (!isActive) - { - Running = false; - _CloseStream(); - _Timer.Stop(); - } - } - } - class CScreenOptionsRecord : CMenu { // Version number for theme files. Increment it, if you've changed something on the theme files! diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj index c08199fc..1b5d5b87 100644 --- a/Vocaluxe/Vocaluxe.csproj +++ b/Vocaluxe/Vocaluxe.csproj @@ -256,6 +256,7 @@ +