Renamed FadeAndStop to FadeAndClose
gstreamer-sharp: Fixed SetMaxVolume gstreamer-sharp: Streams now close properly
This commit is contained in:
1 parent
9fb65de572
commit
ca8fe42a30
6 files changed
+54
-40
No files matched your search
@@ -124,7 +124,7 @@ namespace Vocaluxe.Base
|
|||||||
|
|
||||||
public static void FadeAndStop(int stream, float targetVolume, float seconds)
|
public static void FadeAndStop(int stream, float targetVolume, float seconds)
|
||||||
{
|
{
|
||||||
_Playback.FadeAndStop(stream, targetVolume, seconds);
|
_Playback.FadeAndClose(stream, targetVolume, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetStreamVolume(int stream, float volume)
|
public static void SetStreamVolume(int stream, float volume)
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
CGstreamerAudioWrapper.FadeAndPause(stream, targetVolume, seconds);
|
CGstreamerAudioWrapper.FadeAndPause(stream, targetVolume, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FadeAndStop(int stream, float targetVolume, float seconds)
|
public void FadeAndClose(int stream, float targetVolume, float seconds)
|
||||||
{
|
{
|
||||||
CGstreamerAudioWrapper.FadeAndStop(stream, targetVolume, seconds);
|
CGstreamerAudioWrapper.FadeAndStop(stream, targetVolume, seconds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
Application.Init();
|
Application.Init();
|
||||||
Registry reg = Registry.Get();
|
Registry reg = Registry.Get();
|
||||||
reg.ScanPath(path);
|
reg.ScanPath(path);
|
||||||
|
|
||||||
return Application.IsInitialized;
|
return Application.IsInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,124 +69,129 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
|
|
||||||
public void Close(int stream)
|
public void Close(int stream)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return;
|
return;
|
||||||
Streams[stream].Close();
|
Streams[stream].Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Play(int stream)
|
public void Play(int stream)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return;
|
return;
|
||||||
Streams[stream].Playing = true;
|
Streams[stream].Playing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Play(int stream, bool loop)
|
public void Play(int stream, bool loop)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return;
|
return;
|
||||||
Play(stream);
|
Play(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Pause(int stream)
|
public void Pause(int stream)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return;
|
return;
|
||||||
Streams[stream].Paused = true;
|
Streams[stream].Paused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Stop(int stream)
|
public void Stop(int stream)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return;
|
return;
|
||||||
Streams[stream].Stop();
|
Streams[stream].Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Fade(int stream, float targetVolume, float seconds)
|
public void Fade(int stream, float targetVolume, float seconds)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return;
|
return;
|
||||||
Streams[stream].Fade(targetVolume, seconds);
|
Streams[stream].Fade(targetVolume, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FadeAndPause(int stream, float targetVolume, float seconds)
|
public void FadeAndPause(int stream, float targetVolume, float seconds)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return;
|
return;
|
||||||
Streams[stream].FadeAndPause(targetVolume, seconds);
|
Streams[stream].FadeAndPause(targetVolume, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FadeAndStop(int stream, float targetVolume, float seconds)
|
public void FadeAndClose(int stream, float targetVolume, float seconds)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return;
|
return;
|
||||||
Streams[stream].FadeAndStop(targetVolume, seconds);
|
Streams[stream].FadeAndClose(targetVolume, seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetStreamVolume(int stream, float volume)
|
public void SetStreamVolume(int stream, float volume)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return;
|
return;
|
||||||
Streams[stream].Volume = volume;
|
Streams[stream].Volume = volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetStreamVolumeMax(int stream, float volume)
|
public void SetStreamVolumeMax(int stream, float volume)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return;
|
return;
|
||||||
Streams[stream].MaxVolume = volume;
|
Streams[stream].MaxVolume = volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetLength(int stream)
|
public float GetLength(int stream)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return -1;
|
return -1;
|
||||||
return Streams[stream].Length;
|
return Streams[stream].Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetPosition(int stream)
|
public float GetPosition(int stream)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return -1f;
|
return -1f;
|
||||||
return Streams[stream].Position;
|
return Streams[stream].Position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsPlaying(int stream)
|
public bool IsPlaying(int stream)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return false;
|
return false;
|
||||||
return Streams[stream].Playing;
|
return Streams[stream].Playing;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsPaused(int stream)
|
public bool IsPaused(int stream)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return true;
|
return true;
|
||||||
return Streams[stream].Paused;
|
return Streams[stream].Paused;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsFinished(int stream)
|
public bool IsFinished(int stream)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return true;
|
return true;
|
||||||
return Streams[stream]._Finished;
|
return Streams[stream]._Finished;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetPosition(int stream, float position)
|
public void SetPosition(int stream, float position)
|
||||||
{
|
{
|
||||||
if (stream < 0)
|
if (!Streams.ContainsKey(stream))
|
||||||
return;
|
return;
|
||||||
Streams[stream].Position = position;
|
Streams[stream].Position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
|
var streamsToDelete = new List<int>();
|
||||||
foreach (KeyValuePair<int,CGstreamerSharpAudioStream> stream in Streams)
|
foreach (KeyValuePair<int,CGstreamerSharpAudioStream> stream in Streams)
|
||||||
{
|
{
|
||||||
//if (stream.Value._Closed)
|
if (stream.Value._Closed)
|
||||||
// Streams.Remove(stream.Key);
|
streamsToDelete.Add(stream.Key);
|
||||||
stream.Value.Update();
|
stream.Value.Update();
|
||||||
}
|
}
|
||||||
|
foreach (int key in streamsToDelete)
|
||||||
|
{
|
||||||
|
Streams.Remove(key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CGstreamerSharpAudioStream
|
private class CGstreamerSharpAudioStream
|
||||||
@@ -196,11 +202,12 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
public bool _Finished;
|
public bool _Finished;
|
||||||
|
|
||||||
private bool _Fading;
|
private bool _Fading;
|
||||||
private bool _StopStreamAfterFade;
|
private bool _CloseStreamAfterFade;
|
||||||
private bool _PauseStreamAfterFade;
|
private bool _PauseStreamAfterFade;
|
||||||
private Stopwatch _FadeTimer = new Stopwatch();
|
private Stopwatch _FadeTimer = new Stopwatch();
|
||||||
private float _FadeTime;
|
private float _FadeTime;
|
||||||
private float _FadeVolume;
|
private float _FadeVolume;
|
||||||
|
private float _Volume = 100f;
|
||||||
|
|
||||||
public float _MaxVolume = 100f;
|
public float _MaxVolume = 100f;
|
||||||
public CGstreamerSharpAudioStream(string media, bool prescan)
|
public CGstreamerSharpAudioStream(string media, bool prescan)
|
||||||
@@ -224,13 +231,11 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
|
|
||||||
if (prescan)
|
if (prescan)
|
||||||
_Element.Bus.TimedPopFiltered(0xffffffffffffffff, MessageType.AsyncDone);
|
_Element.Bus.TimedPopFiltered(0xffffffffffffffff, MessageType.AsyncDone);
|
||||||
|
|
||||||
_Element.Bus.Message += OnMessage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMessage(object o, MessageArgs args)
|
private void OnMessage(Message msg)
|
||||||
{
|
{
|
||||||
switch (args.Message.Type)
|
switch (msg.Type)
|
||||||
{
|
{
|
||||||
case MessageType.Eos:
|
case MessageType.Eos:
|
||||||
if (_Loop)
|
if (_Loop)
|
||||||
@@ -247,6 +252,7 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
_Element.SetState(State.Null);
|
_Element.SetState(State.Null);
|
||||||
_Closed = true;
|
_Closed = true;
|
||||||
_Finished = true;
|
_Finished = true;
|
||||||
|
//_Element.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Play(bool loop = false)
|
public void Play(bool loop = false)
|
||||||
@@ -258,6 +264,7 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
_Element.SetState(State.Null);
|
_Element.SetState(State.Null);
|
||||||
|
Position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Fade(float targetVolume, float seconds)
|
public void Fade(float targetVolume, float seconds)
|
||||||
@@ -274,10 +281,10 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
_PauseStreamAfterFade = true;
|
_PauseStreamAfterFade = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FadeAndStop(float targetVolume, float seconds)
|
public void FadeAndClose(float targetVolume, float seconds)
|
||||||
{
|
{
|
||||||
Fade(targetVolume, seconds);
|
Fade(targetVolume, seconds);
|
||||||
_StopStreamAfterFade = true;
|
_CloseStreamAfterFade = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float Volume
|
public float Volume
|
||||||
@@ -288,8 +295,9 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_Element["volume"] = (double) (value / 100d * (_MaxVolume / 100d));
|
_Volume = value;
|
||||||
System.Console.WriteLine(value);
|
_Element["volume"] = (double) ((value / 100d) * (_MaxVolume / 100d));
|
||||||
|
Console.WriteLine((double) (value / 100d * (_MaxVolume / 100d)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,7 +310,7 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
_MaxVolume = value;
|
_MaxVolume = value;
|
||||||
Volume = Volume * (MaxVolume / 100f);
|
Volume = _Volume;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,18 +366,24 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
|
while (_Element.Bus.HavePending())
|
||||||
|
{
|
||||||
|
OnMessage(_Element.Bus.Pop());
|
||||||
|
}
|
||||||
|
|
||||||
if (_Fading)
|
if (_Fading)
|
||||||
{
|
{
|
||||||
if (_FadeTimer.ElapsedMilliseconds < _FadeTime * 1000f)
|
if (_FadeTimer.ElapsedMilliseconds < (_FadeTime * 1000f))
|
||||||
Volume = (_FadeTimer.ElapsedMilliseconds / 10f) / _FadeTime;
|
Volume = ((_FadeTimer.ElapsedMilliseconds) / (_FadeTime * 1000f)) * 100f;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_StopStreamAfterFade)
|
Volume = _FadeVolume;
|
||||||
Stop();
|
if (_CloseStreamAfterFade)
|
||||||
|
Close();
|
||||||
if (_PauseStreamAfterFade)
|
if (_PauseStreamAfterFade)
|
||||||
Paused = true;
|
Paused = true;
|
||||||
|
|
||||||
_StopStreamAfterFade = false;
|
_CloseStreamAfterFade = false;
|
||||||
_PauseStreamAfterFade = false;
|
_PauseStreamAfterFade = false;
|
||||||
_Fading = false;
|
_Fading = false;
|
||||||
_FadeTimer.Reset();
|
_FadeTimer.Reset();
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FadeAndStop(int stream, float targetVolume, float seconds)
|
public void FadeAndClose(int stream, float targetVolume, float seconds)
|
||||||
{
|
{
|
||||||
if (_Initialized)
|
if (_Initialized)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FadeAndStop(int stream, float targetVolume, float seconds)
|
public void FadeAndClose(int stream, float targetVolume, float seconds)
|
||||||
{
|
{
|
||||||
if (_Initialized)
|
if (_Initialized)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace Vocaluxe.Lib.Sound
|
|||||||
void Stop(int stream);
|
void Stop(int stream);
|
||||||
void Fade(int stream, float targetVolume, float seconds);
|
void Fade(int stream, float targetVolume, float seconds);
|
||||||
void FadeAndPause(int stream, float targetVolume, float seconds);
|
void FadeAndPause(int stream, float targetVolume, float seconds);
|
||||||
void FadeAndStop(int stream, float targetVolume, float seconds);
|
void FadeAndClose(int stream, float targetVolume, float seconds);
|
||||||
void SetStreamVolume(int stream, float volume);
|
void SetStreamVolume(int stream, float volume);
|
||||||
void SetStreamVolumeMax(int stream, float volume);
|
void SetStreamVolumeMax(int stream, float volume);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user