From 9a6f1f541a810379fa39c59f31b49aad9fa07066 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sun, 19 Feb 2012 16:17:25 +0100 Subject: [PATCH 1/3] initial develop commit --- Vocaluxe/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Vocaluxe/Program.cs b/Vocaluxe/Program.cs index 42eda947..0f457b11 100644 --- a/Vocaluxe/Program.cs +++ b/Vocaluxe/Program.cs @@ -12,6 +12,7 @@ using Vocaluxe.Menu; namespace Vocaluxe { + // just a small comment for the new develop branch static class MainProgram { static SplashScreen _SplashScreen; From 5fb3280a81019a6b5f0d38fc6141538aa9e3d1c4 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sun, 19 Feb 2012 19:15:33 +0100 Subject: [PATCH 2/3] added FadeAndPause. you can test in in screen test (T in main screen), just add a "Test.mp3" to Output folder. --- Vocaluxe/Base/CSound.cs | 5 ++++ Vocaluxe/Lib/Sound/CBassPlay.cs | 29 ++++++++++++++++++++++++ Vocaluxe/Lib/Sound/CNAudioPlay.cs | 30 ++++++++++++++++++++++++ Vocaluxe/Lib/Sound/COpenALPlay.cs | 26 +++++++++++++++++++++ Vocaluxe/Lib/Sound/CPortAudioPlay.cs | 27 ++++++++++++++++++++++ Vocaluxe/Lib/Sound/IPlayback.cs | 1 + Vocaluxe/Screens/CScreenMain.cs | 4 ++++ Vocaluxe/Screens/CScreenTest.cs | 34 ++++++++++++++++++++++++++++ 8 files changed, 156 insertions(+) diff --git a/Vocaluxe/Base/CSound.cs b/Vocaluxe/Base/CSound.cs index 0033420f..b14f5e45 100644 --- a/Vocaluxe/Base/CSound.cs +++ b/Vocaluxe/Base/CSound.cs @@ -101,6 +101,11 @@ namespace Vocaluxe.Base _Playback.Fade(Stream, TargetVolume, Seconds); } + public static void FadeAndPause(int Stream, float TargetVolume, float Seconds) + { + _Playback.FadeAndPause(Stream, TargetVolume, Seconds); + } + public static void FadeAndStop(int Stream, float TargetVolume, float Seconds) { _Playback.FadeAndStop(Stream, TargetVolume, Seconds); diff --git a/Vocaluxe/Lib/Sound/CBassPlay.cs b/Vocaluxe/Lib/Sound/CBassPlay.cs index f9f79c9a..86148184 100644 --- a/Vocaluxe/Lib/Sound/CBassPlay.cs +++ b/Vocaluxe/Lib/Sound/CBassPlay.cs @@ -17,6 +17,7 @@ namespace Vocaluxe.Lib.Sound private bool _Initialized = false; private List _Streams; private SYNCPROC _SyncSlideAndStop; + private SYNCPROC _SyncSlideAndPause; private Object MutexAudioStreams = new Object(); @@ -48,6 +49,7 @@ namespace Vocaluxe.Lib.Sound ok = Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero); _Streams = new List(); _SyncSlideAndStop = new SYNCPROC(EndSync); + _SyncSlideAndPause = new SYNCPROC(PauseSync); } catch (Exception) { @@ -219,6 +221,22 @@ namespace Vocaluxe.Lib.Sound } } + public void FadeAndPause(int Stream, float TargetVolume, float Seconds) + { + if (_Initialized) + { + lock (MutexAudioStreams) + { + if (AlreadyAdded(Stream)) + { + Bass.BASS_ChannelSlideAttribute(Stream, BASSAttribute.BASS_ATTRIB_VOL, TargetVolume / 100f, (int)Math.Round(Seconds * 1000f)); + Bass.BASS_ChannelSetSync(Stream, BASSSync.BASS_SYNC_SLIDE, 0L, _SyncSlideAndPause, IntPtr.Zero); + } + } + + } + } + public void FadeAndStop(int Stream, float TargetVolume, float Seconds) { if (_Initialized) @@ -372,6 +390,17 @@ namespace Vocaluxe.Lib.Sound return -1; } + private void PauseSync(int handle, int Stream, int data, IntPtr user) + { + if (_Initialized) + { + if (AlreadyAdded(Stream)) + { + Pause(Stream); + } + } + } + private void EndSync(int handle, int Stream, int data, IntPtr user) { if (_Initialized) diff --git a/Vocaluxe/Lib/Sound/CNAudioPlay.cs b/Vocaluxe/Lib/Sound/CNAudioPlay.cs index 8269ca0b..bfe52bf9 100644 --- a/Vocaluxe/Lib/Sound/CNAudioPlay.cs +++ b/Vocaluxe/Lib/Sound/CNAudioPlay.cs @@ -38,6 +38,7 @@ namespace Vocaluxe.Lib.Sound private float _targetVolume; private float _startVolume; private bool _closeStreamAfterFade = false; + private bool _pauseStreamAfterFade = false; private bool _fading = false; public int Handle; @@ -80,6 +81,7 @@ namespace Vocaluxe.Lib.Sound _CurrentTime = Position; _Timer.Start(); } + _pauseStreamAfterFade = false; } } @@ -236,6 +238,9 @@ namespace Vocaluxe.Lib.Sound if (_closeStreamAfterFade) return false; + + if (_pauseStreamAfterFade) + Pause(); } return true; } @@ -256,6 +261,15 @@ namespace Vocaluxe.Lib.Sound _fadeTimer.Start(); } + public void FadeAndPause(float TargetVolume, float FadeTime) + { + if (!_loaded || _volumeStream == null) + return; + + _pauseStreamAfterFade = true; + Fade(TargetVolume, FadeTime); + } + public void FadeAndStop(float TargetVolume, float FadeTime) { if (!_loaded || _volumeStream == null) @@ -526,6 +540,22 @@ namespace Vocaluxe.Lib.Sound } } + public void FadeAndPause(int Stream, float TargetVolume, float Seconds) + { + if (_Initialized) + { + lock (MutexAudioStreams) + { + if (AlreadyAdded(Stream)) + { + int index = GetStreamIndex(Stream); + _Streams[index].FadeAndPause(TargetVolume, Seconds); + } + } + + } + } + public void FadeAndStop(int Stream, float TargetVolume, float Seconds) { if (_Initialized) diff --git a/Vocaluxe/Lib/Sound/COpenALPlay.cs b/Vocaluxe/Lib/Sound/COpenALPlay.cs index 97fdb2bb..a789fc2b 100644 --- a/Vocaluxe/Lib/Sound/COpenALPlay.cs +++ b/Vocaluxe/Lib/Sound/COpenALPlay.cs @@ -188,6 +188,21 @@ namespace Vocaluxe.Lib.Sound } } + public void FadeAndPause(int Stream, float TargetVolume, float Seconds) + { + if (_Initialized) + { + lock (MutexDecoder) + { + if (AlreadyAdded(Stream)) + { + _Decoder[GetStreamIndex(Stream)].FadeAndPause(TargetVolume, Seconds); + } + } + + } + } + public void FadeAndStop(int Stream, float TargetVolume, float Seconds) { if (_Initialized) @@ -390,6 +405,7 @@ namespace Vocaluxe.Lib.Sound private float _targetVolume = 1f; private float _startVolume = 1f; private bool _closeStreamAfterFade = false; + private bool _pauseStreamAfterFade = false; private bool _fading = false; @@ -528,6 +544,12 @@ namespace Vocaluxe.Lib.Sound _fadeTimer.Start(); } + public void FadeAndPause(float TargetVolume, float FadeTime) + { + _pauseStreamAfterFade = true; + Fade(TargetVolume, FadeTime); + } + public void FadeAndStop(float TargetVolume, float FadeTime, CLOSEPROC close_proc, int StreamID) { _Closeproc = close_proc; @@ -539,6 +561,7 @@ namespace Vocaluxe.Lib.Sound public void Play() { Paused = false; + _pauseStreamAfterFade = false; AL.SourcePlay(_source); } @@ -756,6 +779,9 @@ namespace Vocaluxe.Lib.Sound if (_closeStreamAfterFade) _terminated = true; + + if (_pauseStreamAfterFade) + Paused = true; } } } diff --git a/Vocaluxe/Lib/Sound/CPortAudioPlay.cs b/Vocaluxe/Lib/Sound/CPortAudioPlay.cs index ddbee066..577d5d1a 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioPlay.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioPlay.cs @@ -172,6 +172,21 @@ namespace Vocaluxe.Lib.Sound } } + public void FadeAndPause(int Stream, float TargetVolume, float Seconds) + { + if (_Initialized) + { + lock (MutexDecoder) + { + if (AlreadyAdded(Stream)) + { + _Decoder[GetStreamIndex(Stream)].FadeAndPause(TargetVolume, Seconds); + } + } + + } + } + public void FadeAndStop(int Stream, float TargetVolume, float Seconds) { if (_Initialized) @@ -366,6 +381,7 @@ namespace Vocaluxe.Lib.Sound private float _targetVolume = 1f; private float _startVolume = 1f; private bool _closeStreamAfterFade = false; + private bool _pauseStreamAfterFade = false; private bool _fading = false; @@ -507,6 +523,13 @@ namespace Vocaluxe.Lib.Sound _fadeTimer.Start(); } + public void FadeAndPause(float TargetVolume, float FadeTime) + { + _pauseStreamAfterFade = true; + + Fade(TargetVolume, FadeTime); + } + public void FadeAndStop(float TargetVolume, float FadeTime, CLOSEPROC close_proc, int StreamID) { _Closeproc = close_proc; @@ -519,6 +542,7 @@ namespace Vocaluxe.Lib.Sound public void Play() { Paused = false; + _pauseStreamAfterFade = false; errorCheck("StartStream", PortAudio.Pa_StartStream(_Ptr)); } @@ -889,6 +913,9 @@ namespace Vocaluxe.Lib.Sound if (_closeStreamAfterFade) _terminated = true; + + if (_pauseStreamAfterFade) + Paused = true; } } } diff --git a/Vocaluxe/Lib/Sound/IPlayback.cs b/Vocaluxe/Lib/Sound/IPlayback.cs index 0c93d68f..a1fbd9b1 100644 --- a/Vocaluxe/Lib/Sound/IPlayback.cs +++ b/Vocaluxe/Lib/Sound/IPlayback.cs @@ -35,6 +35,7 @@ namespace Vocaluxe.Lib.Sound void Pause(int Stream); void Stop(int Stream); void Fade(int Stream, float TargetVolume, float Seconds); + void FadeAndPause(int Stream, float TargetVolume, float Seconds); void FadeAndStop(int Stream, float TargetVolume, float Seconds); void SetStreamVolume(int Stream, float Volume); diff --git a/Vocaluxe/Screens/CScreenMain.cs b/Vocaluxe/Screens/CScreenMain.cs index fa95c8b7..402feb89 100644 --- a/Vocaluxe/Screens/CScreenMain.cs +++ b/Vocaluxe/Screens/CScreenMain.cs @@ -65,6 +65,10 @@ namespace Vocaluxe.Screens CGraphics.FadeTo(EScreens.ScreenSong); break; + case Keys.T: + CGraphics.FadeTo(EScreens.ScreenTest); + break; + case Keys.Enter: if (Buttons[htButtons(ButtonSing)].Selected) CGraphics.FadeTo(EScreens.ScreenSong); diff --git a/Vocaluxe/Screens/CScreenTest.cs b/Vocaluxe/Screens/CScreenTest.cs index 848f8516..277b96cc 100644 --- a/Vocaluxe/Screens/CScreenTest.cs +++ b/Vocaluxe/Screens/CScreenTest.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Text; using System.Windows.Forms; @@ -14,6 +15,8 @@ namespace Vocaluxe.Screens // Version number for theme files. Increment it, if you've changed something on the theme files! const int ScreenVersion = 1; + private int _TestMusic = -1; + public CScreenTest() { Init(); @@ -45,6 +48,18 @@ namespace Vocaluxe.Screens case Keys.Enter: CGraphics.FadeTo(EScreens.ScreenMain); break; + + case Keys.F: + FadeAndPause(); + break; + + case Keys.S: + PlayFile(); + break; + + case Keys.P: + PauseFile(); + break; } } @@ -86,5 +101,24 @@ namespace Vocaluxe.Screens { return base.Draw(); } + + private void PlayFile() + { + if (_TestMusic == -1) + _TestMusic = CSound.Load(Path.Combine(Environment.CurrentDirectory, "Test.mp3")); + + CSound.Play(_TestMusic); + CSound.Fade(_TestMusic, 100f, 2f); + } + + private void PauseFile() + { + CSound.Pause(_TestMusic); + } + + private void FadeAndPause() + { + CSound.FadeAndPause(_TestMusic, 0f, 2f); + } } } From 137e39cae3fc305d15f78e59fe66d396d6c22296 Mon Sep 17 00:00:00 2001 From: Alexander Eckart Date: Sun, 19 Feb 2012 19:41:35 +0100 Subject: [PATCH 3/3] reset playback position on stop (same behavior like in BASS) --- Vocaluxe/Lib/Sound/COpenALPlay.cs | 1 + Vocaluxe/Lib/Sound/CPortAudioPlay.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/Vocaluxe/Lib/Sound/COpenALPlay.cs b/Vocaluxe/Lib/Sound/COpenALPlay.cs index a789fc2b..92d07951 100644 --- a/Vocaluxe/Lib/Sound/COpenALPlay.cs +++ b/Vocaluxe/Lib/Sound/COpenALPlay.cs @@ -568,6 +568,7 @@ namespace Vocaluxe.Lib.Sound public void Stop() { AL.SourceStop(_source); + Skip(0f); } public bool Loop diff --git a/Vocaluxe/Lib/Sound/CPortAudioPlay.cs b/Vocaluxe/Lib/Sound/CPortAudioPlay.cs index 577d5d1a..b2814f0e 100644 --- a/Vocaluxe/Lib/Sound/CPortAudioPlay.cs +++ b/Vocaluxe/Lib/Sound/CPortAudioPlay.cs @@ -549,6 +549,7 @@ namespace Vocaluxe.Lib.Sound public void Stop() { errorCheck("StartStream", PortAudio.Pa_StopStream(_Ptr)); + Skip(0f); } public bool Loop