diff --git a/ProjectObsidian.SourceGenerators b/ProjectObsidian.SourceGenerators index 61759b9..e073aba 160000 --- a/ProjectObsidian.SourceGenerators +++ b/ProjectObsidian.SourceGenerators @@ -1 +1 @@ -Subproject commit 61759b92ed2b80729ddf3fd8041de5c14850189d +Subproject commit e073aba49148a23d952902a851b9839d3a8950c0 diff --git a/ProjectObsidian/ProtoFlux/Audio/AudioAdder.cs b/ProjectObsidian/ProtoFlux/Audio/AudioAdder.cs index 2615507..b028558 100644 --- a/ProjectObsidian/ProtoFlux/Audio/AudioAdder.cs +++ b/ProjectObsidian/ProtoFlux/Audio/AudioAdder.cs @@ -8,19 +8,11 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class AudioAdderProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class AudioAdderProxy : DualInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; + public override int ChannelCount => AudioInput?.ChannelCount ?? AudioInput2?.ChannelCount ?? 0; - public IWorldAudioDataSource AudioInput2; - - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => AudioInput?.ChannelCount ?? AudioInput2?.ChannelCount ?? 0; - - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive) { @@ -49,106 +41,7 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio")] - public class AudioAdder : ProxyVoidNode, IExecutionChangeListener + public class AudioAdder : DualInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - - [ChangeListener] - public readonly ObjectInput AudioInput2; - - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(AudioAdderProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(AudioAdderProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(AudioAdderProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - AudioAdderProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) - { - AudioAdderProxy proxy = GetProxy(context); - if (proxy == null) - { - return; - } - proxy.AudioInput = AudioInput.Evaluate(context); - proxy.AudioInput2 = AudioInput2.Evaluate(context); - } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - AudioAdderProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public AudioAdder() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/AudioClamp.cs b/ProjectObsidian/ProtoFlux/Audio/AudioClamp.cs index 19eac3e..36b9081 100644 --- a/ProjectObsidian/ProtoFlux/Audio/AudioClamp.cs +++ b/ProjectObsidian/ProtoFlux/Audio/AudioClamp.cs @@ -8,17 +8,11 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class AudioClampProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class AudioClampProxy : SingleInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; + public override int ChannelCount => AudioInput?.ChannelCount ?? 0; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => AudioInput?.ChannelCount ?? 0; - - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive || AudioInput == null || !AudioInput.IsActive) { @@ -39,102 +33,7 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio")] - public class AudioClamp : ProxyVoidNode, IExecutionChangeListener + public class AudioClamp : SingleInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(AudioClampProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(AudioClampProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(AudioClampProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - AudioClampProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) - { - AudioClampProxy proxy = GetProxy(context); - if (proxy == null) - { - return; - } - proxy.AudioInput = AudioInput.Evaluate(context); - } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - AudioClampProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public AudioClamp() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/AudioDelay.cs b/ProjectObsidian/ProtoFlux/Audio/AudioDelay.cs index 03e920a..9a631aa 100644 --- a/ProjectObsidian/ProtoFlux/Audio/AudioDelay.cs +++ b/ProjectObsidian/ProtoFlux/Audio/AudioDelay.cs @@ -12,25 +12,19 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class AudioDelayProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class AudioDelayProxy : SingleInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; - public int delayMilliseconds; public float feedback; public float DryWet; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => AudioInput?.ChannelCount ?? 0; + public override int ChannelCount => AudioInput?.ChannelCount ?? 0; public DelayController _controller = new(); - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { lock (_controller) { @@ -66,11 +60,8 @@ protected override void OnStart() } [NodeName("Delay")] [NodeCategory("Obsidian/Audio/Effects")] - public class AudioDelay : ProxyVoidNode, IExecutionChangeListener + public class AudioDelay : SingleInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - [ChangeListener] public readonly ValueInput DelayMilliseconds; @@ -80,86 +71,14 @@ public class AudioDelay : ProxyVoidNode, IE [ChangeListener] public readonly ValueInput DryWet; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(AudioDelayProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(AudioDelayProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(AudioDelayProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - AudioDelayProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { AudioDelayProxy proxy = GetProxy(context); if (proxy == null) { return; } - proxy.AudioInput = AudioInput.Evaluate(context); + base.Changed(context); proxy.delayMilliseconds = DelayMilliseconds.Evaluate(context); lock (proxy._controller) { @@ -171,16 +90,5 @@ public void Changed(FrooxEngineContext context) proxy.feedback = Feedback.Evaluate(context); proxy.DryWet = DryWet.Evaluate(context); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - AudioDelayProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public AudioDelay() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/AudioMultiply.cs b/ProjectObsidian/ProtoFlux/Audio/AudioMultiply.cs index 0ae4eab..d4e6702 100644 --- a/ProjectObsidian/ProtoFlux/Audio/AudioMultiply.cs +++ b/ProjectObsidian/ProtoFlux/Audio/AudioMultiply.cs @@ -8,19 +8,14 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class AudioMultiplyProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class AudioMultiplyProxy : SingleInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; public float Value; - public bool Active; + public override int ChannelCount => AudioInput?.ChannelCount ?? 0; - public bool IsActive => Active; - - public int ChannelCount => AudioInput?.ChannelCount ?? 0; - - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive || AudioInput == null) { @@ -44,106 +39,20 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio")] - public class AudioMultiply : ProxyVoidNode, IExecutionChangeListener + public class AudioMultiply : SingleInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - [ChangeListener] public readonly ValueInput Value; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(AudioMultiplyProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(AudioMultiplyProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(AudioMultiplyProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - AudioMultiplyProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { AudioMultiplyProxy proxy = GetProxy(context); if (proxy == null) { return; } - proxy.AudioInput = AudioInput.Evaluate(context); + base.Changed(context); proxy.Value = Value.Evaluate(context); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - AudioMultiplyProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public AudioMultiply() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/AudioSubtractor.cs b/ProjectObsidian/ProtoFlux/Audio/AudioSubtractor.cs index da8c999..8ff14bf 100644 --- a/ProjectObsidian/ProtoFlux/Audio/AudioSubtractor.cs +++ b/ProjectObsidian/ProtoFlux/Audio/AudioSubtractor.cs @@ -8,19 +8,11 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class AudioSubtractorProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class AudioSubtractorProxy : DualInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; + public override int ChannelCount => AudioInput?.ChannelCount ?? AudioInput2?.ChannelCount ?? 0; - public IWorldAudioDataSource AudioInput2; - - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => AudioInput?.ChannelCount ?? AudioInput2?.ChannelCount ?? 0; - - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive) { @@ -55,106 +47,7 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio")] - public class AudioSubtractor : ProxyVoidNode, IExecutionChangeListener + public class AudioSubtractor : DualInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - - [ChangeListener] - public readonly ObjectInput AudioInput2; - - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(AudioSubtractorProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(AudioSubtractorProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(AudioSubtractorProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - AudioSubtractorProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) - { - AudioSubtractorProxy proxy = GetProxy(context); - if (proxy == null) - { - return; - } - proxy.AudioInput = AudioInput.Evaluate(context); - proxy.AudioInput2 = AudioInput2.Evaluate(context); - } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - AudioSubtractorProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public AudioSubtractor() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/BandPassFilterNode.cs b/ProjectObsidian/ProtoFlux/Audio/BandPassFilterNode.cs index 3fed7e7..c98c957 100644 --- a/ProjectObsidian/ProtoFlux/Audio/BandPassFilterNode.cs +++ b/ProjectObsidian/ProtoFlux/Audio/BandPassFilterNode.cs @@ -9,25 +9,19 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class BandPassFilterProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class BandPassFilterProxy : SingleInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; - public float LowFrequency; public float HighFrequency; public float Resonance; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => AudioInput?.ChannelCount ?? 0; + public override int ChannelCount => AudioInput?.ChannelCount ?? 0; private BandPassFilterController _controller = new(); - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { lock (_controller) { @@ -49,11 +43,8 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio/Filters")] - public class BandPassFilter : ProxyVoidNode, IExecutionChangeListener + public class BandPassFilter : SingleInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - [ChangeListener] [DefaultValueAttribute(20f)] public readonly ValueInput LowFrequency; @@ -66,100 +57,17 @@ public class BandPassFilter : ProxyVoidNode Resonance; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(BandPassFilterProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(BandPassFilterProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(BandPassFilterProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - BandPassFilterProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { BandPassFilterProxy proxy = GetProxy(context); if (proxy == null) { return; } - proxy.AudioInput = AudioInput.Evaluate(context); + base.Changed(context); proxy.LowFrequency = LowFrequency.Evaluate(context, 20f); proxy.HighFrequency = HighFrequency.Evaluate(context, 20000f); proxy.Resonance = Resonance.Evaluate(context, 1.41f); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - BandPassFilterProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public BandPassFilter() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/Base Classes/AudioGeneratorNode.cs b/ProjectObsidian/ProtoFlux/Audio/Base Classes/AudioGeneratorNode.cs new file mode 100644 index 0000000..f65ad3b --- /dev/null +++ b/ProjectObsidian/ProtoFlux/Audio/Base Classes/AudioGeneratorNode.cs @@ -0,0 +1,111 @@ +using System; +using Awwdio; +using Elements.Assets; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio; + +public abstract class AudioGeneratorNodeProxy : ProtoFluxEngineProxy, IWorldAudioDataSource +{ + public bool IsActive => Active; + + public abstract int ChannelCount { get; } + + public bool Active; + + public abstract void Read(Span buffer, AudioSimulator system) where S : unmanaged, IAudioSample; +} + +[NodeCategory("Obsidian/Audio")] +public abstract class AudioGeneratorNode

: ProxyVoidNode, IExecutionChangeListener where P : AudioGeneratorNodeProxy, new() +{ + public readonly ObjectOutput AudioOutput; + + private ObjectStore> _enabledChangedHandler; + + private ObjectStore _activeChangedHandler; + + public bool ValueListensToChanges { get; private set; } + + private bool ShouldListen(P proxy) + { + if (proxy.Enabled) + { + return proxy.Slot.IsActive; + } + return false; + } + + protected override void ProxyAdded(P proxy, FrooxEngineContext context) + { + base.ProxyAdded(proxy, context); + NodeContextPath path = context.CaptureContextPath(); + ProtoFluxNodeGroup group = context.Group; + context.GetEventDispatcher(out var dispatcher); + Action enabledHandler = delegate + { + dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) + { + UpdateListenerState(c); + }); + }; + SlotEvent activeHandler = delegate + { + dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) + { + UpdateListenerState(c); + }); + }; + proxy.EnabledField.Changed += enabledHandler; + proxy.Slot.ActiveChanged += activeHandler; + _enabledChangedHandler.Write(enabledHandler, context); + _activeChangedHandler.Write(activeHandler, context); + ValueListensToChanges = ShouldListen(proxy); + proxy.Active = ValueListensToChanges; + } + + protected override void ProxyRemoved(P proxy, FrooxEngineContext context, bool inUseByAnotherInstance) + { + if (!inUseByAnotherInstance) + { + proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); + proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); + _enabledChangedHandler.Clear(context); + _activeChangedHandler.Clear(context); + proxy.Active = false; + } + } + + protected void UpdateListenerState(FrooxEngineContext context) + { + P proxy = GetProxy(context); + if (proxy != null) + { + bool shouldListen = ShouldListen(proxy); + if (shouldListen != ValueListensToChanges) + { + ValueListensToChanges = shouldListen; + context.Group.MarkChangeTrackingDirty(); + proxy.Active = shouldListen; + } + } + } + + public virtual void Changed(FrooxEngineContext context) + { + + } + + protected override void ComputeOutputs(FrooxEngineContext context) + { + P proxy = GetProxy(context); + AudioOutput.Write(proxy, context); + } + + public AudioGeneratorNode() + { + AudioOutput = new ObjectOutput(this); + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/Base Classes/DualInputAudioGeneratorNode.cs b/ProjectObsidian/ProtoFlux/Audio/Base Classes/DualInputAudioGeneratorNode.cs new file mode 100644 index 0000000..a2d615f --- /dev/null +++ b/ProjectObsidian/ProtoFlux/Audio/Base Classes/DualInputAudioGeneratorNode.cs @@ -0,0 +1,31 @@ +using System; +using Awwdio; +using Elements.Assets; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio +{ + public abstract class DualInputAudioGeneratorNodeProxy : SingleInputAudioGeneratorNodeProxy + { + public IWorldAudioDataSource AudioInput2; + } + [NodeCategory("Obsidian/Audio")] + public abstract class DualInputAudioGeneratorNode

: SingleInputAudioGeneratorNode

where P : DualInputAudioGeneratorNodeProxy, new() + { + [ChangeListener] + public readonly ObjectInput AudioInput2; + + public override void Changed(FrooxEngineContext context) + { + P proxy = GetProxy(context); + if (proxy == null) + { + return; + } + base.Changed(context); + proxy.AudioInput2 = AudioInput2.Evaluate(context); + } + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/Base Classes/SingleInputAudioGeneratorNode.cs b/ProjectObsidian/ProtoFlux/Audio/Base Classes/SingleInputAudioGeneratorNode.cs new file mode 100644 index 0000000..541bbe9 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/Audio/Base Classes/SingleInputAudioGeneratorNode.cs @@ -0,0 +1,31 @@ +using System; +using Awwdio; +using Elements.Assets; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio +{ + public abstract class SingleInputAudioGeneratorNodeProxy : AudioGeneratorNodeProxy + { + public IWorldAudioDataSource AudioInput; + } + [NodeCategory("Obsidian/Audio")] + public abstract class SingleInputAudioGeneratorNode

: AudioGeneratorNode

where P : SingleInputAudioGeneratorNodeProxy, new() + { + [ChangeListener] + public readonly ObjectInput AudioInput; + + public override void Changed(FrooxEngineContext context) + { + P proxy = GetProxy(context); + if (proxy == null) + { + return; + } + base.Changed(context); + proxy.AudioInput = AudioInput.Evaluate(context); + } + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/ButterworthFilterNode.cs b/ProjectObsidian/ProtoFlux/Audio/ButterworthFilterNode.cs index 4037ff0..5ef8336 100644 --- a/ProjectObsidian/ProtoFlux/Audio/ButterworthFilterNode.cs +++ b/ProjectObsidian/ProtoFlux/Audio/ButterworthFilterNode.cs @@ -9,25 +9,19 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class ButterworthFilterProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class ButterworthFilterProxy : SingleInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; - public bool LowPass; public float Frequency; public float Resonance; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => AudioInput?.ChannelCount ?? 0; + public override int ChannelCount => AudioInput?.ChannelCount ?? 0; private ButterworthFilterController _controller = new(); - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { lock (_controller) { @@ -49,11 +43,8 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio/Filters")] - public class ButterworthFilter : ProxyVoidNode, IExecutionChangeListener + public class ButterworthFilter : SingleInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - [ChangeListener] public readonly ValueInput LowPass; @@ -65,100 +56,17 @@ public class ButterworthFilter : ProxyVoidNode Resonance; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(ButterworthFilterProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(ButterworthFilterProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(ButterworthFilterProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - ButterworthFilterProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { ButterworthFilterProxy proxy = GetProxy(context); if (proxy == null) { return; } - proxy.AudioInput = AudioInput.Evaluate(context); + base.Changed(context); proxy.LowPass = LowPass.Evaluate(context); proxy.Frequency = Frequency.Evaluate(context, 20f); proxy.Resonance = Resonance.Evaluate(context, 1.41f); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - ButterworthFilterProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public ButterworthFilter() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/ChannelSplitter.cs b/ProjectObsidian/ProtoFlux/Audio/ChannelSplitter.cs index dcc2f44..f1f9519 100644 --- a/ProjectObsidian/ProtoFlux/Audio/ChannelSplitter.cs +++ b/ProjectObsidian/ProtoFlux/Audio/ChannelSplitter.cs @@ -8,19 +8,13 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class ChannelSplitterProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class ChannelSplitterProxy : SingleInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; - public int Channel; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => 1; + public override int ChannelCount => 1; - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive) { @@ -72,106 +66,20 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio")] - public class ChannelSplitter : ProxyVoidNode, IExecutionChangeListener + public class ChannelSplitter : SingleInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - [ChangeListener] public readonly ValueInput Channel; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(ChannelSplitterProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(ChannelSplitterProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(ChannelSplitterProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - ChannelSplitterProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { ChannelSplitterProxy proxy = GetProxy(context); if (proxy == null) { return; } - proxy.AudioInput = AudioInput.Evaluate(context); + base.Changed(context); proxy.Channel = Channel.Evaluate(context); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - ChannelSplitterProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public ChannelSplitter() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/EMA_IIR_SmoothSignalNode.cs b/ProjectObsidian/ProtoFlux/Audio/EMA_IIR_SmoothSignalNode.cs index fb6d566..c009bd9 100644 --- a/ProjectObsidian/ProtoFlux/Audio/EMA_IIR_SmoothSignalNode.cs +++ b/ProjectObsidian/ProtoFlux/Audio/EMA_IIR_SmoothSignalNode.cs @@ -9,19 +9,13 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class EMA_IIR_SmoothSignalProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class EMA_IIR_SmoothSignalProxy : SingleInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; - public float SmoothingFactor; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => AudioInput?.ChannelCount ?? 0; + public override int ChannelCount => AudioInput?.ChannelCount ?? 0; - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive || AudioInput == null) { @@ -35,106 +29,20 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio/Filters")] - public class EMA_IIR_SmoothSignal : ProxyVoidNode, IExecutionChangeListener + public class EMA_IIR_SmoothSignal : SingleInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - [ChangeListener] public readonly ValueInput SmoothingFactor; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(EMA_IIR_SmoothSignalProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(EMA_IIR_SmoothSignalProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(EMA_IIR_SmoothSignalProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - EMA_IIR_SmoothSignalProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { EMA_IIR_SmoothSignalProxy proxy = GetProxy(context); if (proxy == null) { return; } - proxy.AudioInput = AudioInput.Evaluate(context); + base.Changed(context); proxy.SmoothingFactor = SmoothingFactor.Evaluate(context); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - EMA_IIR_SmoothSignalProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public EMA_IIR_SmoothSignal() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/FIR_Filter.cs b/ProjectObsidian/ProtoFlux/Audio/FIR_Filter.cs index 2523e85..8b1a4e9 100644 --- a/ProjectObsidian/ProtoFlux/Audio/FIR_Filter.cs +++ b/ProjectObsidian/ProtoFlux/Audio/FIR_Filter.cs @@ -13,17 +13,11 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class FIR_FilterProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class FIR_FilterProxy : SingleInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; - public readonly SyncFieldList Coefficients; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => AudioInput?.ChannelCount ?? 0; + public override int ChannelCount => AudioInput?.ChannelCount ?? 0; public FIR_FilterController _controller = new(); @@ -69,7 +63,7 @@ public void OnElementsAddedOrRemoved(SyncElementList> list, int star _controller.Clear(); } - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { lock (_controller) { @@ -102,11 +96,8 @@ protected override void OnStart() } } [NodeCategory("Obsidian/Audio/Filters")] - public class FIR_Filter : ProxyVoidNode, IExecutionChangeListener + public class FIR_Filter : SingleInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - public readonly ValueInput CoefficientIndex; public readonly ValueInput CoefficientValue; @@ -121,78 +112,6 @@ public class FIR_Filter : ProxyVoidNode, IE public Continuation OnClearCoefficients; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(FIR_FilterProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(FIR_FilterProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(FIR_FilterProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - FIR_FilterProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - private IOperation DoSetCoefficient(FrooxEngineContext context) { FIR_FilterProxy proxy = GetProxy(context); @@ -259,25 +178,8 @@ private IOperation DoClearCoefficients(FrooxEngineContext context) return OnClearCoefficients.Target; } - public void Changed(FrooxEngineContext context) - { - FIR_FilterProxy proxy = GetProxy(context); - if (proxy == null) - { - return; - } - proxy.AudioInput = AudioInput.Evaluate(context); - } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - FIR_FilterProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - public FIR_Filter() { - AudioOutput = new ObjectOutput(this); SetCoefficient = new Operation(this, 0); ClearCoefficients = new Operation(this, 1); } diff --git a/ProjectObsidian/ProtoFlux/Audio/OneSampleDelay.cs b/ProjectObsidian/ProtoFlux/Audio/OneSampleDelay.cs index 7811320..e5fc82f 100644 --- a/ProjectObsidian/ProtoFlux/Audio/OneSampleDelay.cs +++ b/ProjectObsidian/ProtoFlux/Audio/OneSampleDelay.cs @@ -12,23 +12,17 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class OneSampleDelayProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class OneSampleDelayProxy : SingleInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; - public float feedback; public float DryWet; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => AudioInput?.ChannelCount ?? 0; + public override int ChannelCount => AudioInput?.ChannelCount ?? 0; public DelayController _controller = new(); - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { lock (_controller) { @@ -63,110 +57,24 @@ protected override void OnStart() } } [NodeCategory("Obsidian/Audio/Effects")] - public class OneSampleDelay : ProxyVoidNode, IExecutionChangeListener + public class OneSampleDelay : SingleInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - [ChangeListener] public readonly ValueInput Feedback; [ChangeListener] public readonly ValueInput DryWet; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(OneSampleDelayProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(OneSampleDelayProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(OneSampleDelayProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - OneSampleDelayProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { OneSampleDelayProxy proxy = GetProxy(context); if (proxy == null) { return; } - proxy.AudioInput = AudioInput.Evaluate(context); + base.Changed(context); proxy.feedback = Feedback.Evaluate(context); proxy.DryWet = DryWet.Evaluate(context); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - OneSampleDelayProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public OneSampleDelay() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/PhaseModulatorNode.cs b/ProjectObsidian/ProtoFlux/Audio/PhaseModulatorNode.cs index ab57f89..566a3f5 100644 --- a/ProjectObsidian/ProtoFlux/Audio/PhaseModulatorNode.cs +++ b/ProjectObsidian/ProtoFlux/Audio/PhaseModulatorNode.cs @@ -10,21 +10,13 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class PhaseModulatorProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class PhaseModulatorProxy : DualInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; - - public IWorldAudioDataSource AudioInput2; - public float ModulationIndex; - public bool Active; - - public bool IsActive => Active; + public override int ChannelCount => MathX.Min(AudioInput?.ChannelCount ?? 0, AudioInput2?.ChannelCount ?? 0); - public int ChannelCount => MathX.Min(AudioInput?.ChannelCount ?? 0, AudioInput2?.ChannelCount ?? 0); - - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive || AudioInput == null || AudioInput2 == null) { @@ -43,110 +35,20 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio/Effects")] - public class PhaseModulator : ProxyVoidNode, IExecutionChangeListener + public class PhaseModulator : DualInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - - [ChangeListener] - public readonly ObjectInput AudioInput2; - [ChangeListener] public readonly ValueInput ModulationIndex; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(PhaseModulatorProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(PhaseModulatorProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(PhaseModulatorProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - PhaseModulatorProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { PhaseModulatorProxy proxy = GetProxy(context); if (proxy == null) { return; } - proxy.AudioInput = AudioInput.Evaluate(context); - proxy.AudioInput2 = AudioInput2.Evaluate(context); + base.Changed(context); proxy.ModulationIndex = ModulationIndex.Evaluate(context); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - PhaseModulatorProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public PhaseModulator() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/QuadCombiner.cs b/ProjectObsidian/ProtoFlux/Audio/QuadCombiner.cs index 1b39271..3030a42 100644 --- a/ProjectObsidian/ProtoFlux/Audio/QuadCombiner.cs +++ b/ProjectObsidian/ProtoFlux/Audio/QuadCombiner.cs @@ -8,7 +8,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class QuadCombinerProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class QuadCombinerProxy : AudioGeneratorNodeProxy { public IWorldAudioDataSource LeftFront; @@ -18,13 +18,9 @@ public class QuadCombinerProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, public IWorldAudioDataSource RightRear; - public bool Active; + public override int ChannelCount => 4; - public bool IsActive => Active; - - public int ChannelCount => 4; - - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive) { @@ -73,7 +69,7 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio")] - public class QuadCombiner : ProxyVoidNode, IExecutionChangeListener + public class QuadCombiner : AudioGeneratorNode { [ChangeListener] public readonly ObjectInput LeftFront; @@ -87,100 +83,18 @@ public class QuadCombiner : ProxyVoidNode [ChangeListener] public readonly ObjectInput RightRear; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(QuadCombinerProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(QuadCombinerProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(QuadCombinerProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - QuadCombinerProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { QuadCombinerProxy proxy = GetProxy(context); if (proxy == null) { return; } + base.Changed(context); proxy.LeftFront = LeftFront.Evaluate(context); proxy.RightFront = RightFront.Evaluate(context); proxy.LeftRear = LeftRear.Evaluate(context); proxy.RightRear = RightRear.Evaluate(context); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - QuadCombinerProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public QuadCombiner() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/Reverb.cs b/ProjectObsidian/ProtoFlux/Audio/Reverb.cs index b25db08..bec9bb3 100644 --- a/ProjectObsidian/ProtoFlux/Audio/Reverb.cs +++ b/ProjectObsidian/ProtoFlux/Audio/Reverb.cs @@ -13,23 +13,17 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class ReverbProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class ReverbProxy : SingleInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; - public ZitaParameters parameters; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => AudioInput?.ChannelCount ?? 0; + public override int ChannelCount => AudioInput?.ChannelCount ?? 0; private ZitaParameters defaultParameters = new ZitaParameters(); public ReverbController _controller = new(); - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { lock (_controller) { @@ -83,96 +77,21 @@ protected override void OnStart() } } [NodeCategory("Obsidian/Audio/Effects")] - public class Reverb : ProxyVoidNode, IExecutionChangeListener + public class Reverb : SingleInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - [ChangeListener] public readonly ValueInput Parameters; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - private ZitaParameters lastParameters; - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(ReverbProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(ReverbProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(ReverbProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - ReverbProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { ReverbProxy proxy = GetProxy(context); if (proxy == null) { return; } - proxy.AudioInput = AudioInput.Evaluate(context); + base.Changed(context); proxy.parameters = Parameters.Evaluate(context); if (!proxy.parameters.Equals(lastParameters)) { @@ -181,16 +100,5 @@ public void Changed(FrooxEngineContext context) } lastParameters = proxy.parameters; } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - ReverbProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public Reverb() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/RingModulatorNode.cs b/ProjectObsidian/ProtoFlux/Audio/RingModulatorNode.cs index 579c2b5..4b7930a 100644 --- a/ProjectObsidian/ProtoFlux/Audio/RingModulatorNode.cs +++ b/ProjectObsidian/ProtoFlux/Audio/RingModulatorNode.cs @@ -11,21 +11,13 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class RingModulatorProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class RingModulatorProxy : DualInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; - - public IWorldAudioDataSource AudioInput2; - public float ModulationIndex; - public bool Active; - - public bool IsActive => Active; + public override int ChannelCount => MathX.Min(AudioInput?.ChannelCount ?? 0, AudioInput2?.ChannelCount ?? 0); - public int ChannelCount => MathX.Min(AudioInput?.ChannelCount ?? 0, AudioInput2?.ChannelCount ?? 0); - - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive || AudioInput == null || AudioInput2 == null) { @@ -44,110 +36,20 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio/Effects")] - public class RingModulator : ProxyVoidNode, IExecutionChangeListener + public class RingModulator : DualInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - - [ChangeListener] - public readonly ObjectInput AudioInput2; - [ChangeListener] public readonly ValueInput ModulationIndex; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(RingModulatorProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(RingModulatorProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(RingModulatorProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - RingModulatorProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { RingModulatorProxy proxy = GetProxy(context); if (proxy == null) { return; } - proxy.AudioInput = AudioInput.Evaluate(context); - proxy.AudioInput2 = AudioInput2.Evaluate(context); + base.Changed(context); proxy.ModulationIndex = ModulationIndex.Evaluate(context); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - RingModulatorProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public RingModulator() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/SawtoothGenerator.cs b/ProjectObsidian/ProtoFlux/Audio/SawtoothGenerator.cs index 46e4c29..de3278c 100644 --- a/ProjectObsidian/ProtoFlux/Audio/SawtoothGenerator.cs +++ b/ProjectObsidian/ProtoFlux/Audio/SawtoothGenerator.cs @@ -10,7 +10,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class SawtoothGeneratorProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class SawtoothGeneratorProxy : AudioGeneratorNodeProxy { public float Frequency; @@ -22,15 +22,11 @@ public class SawtoothGeneratorProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSou private float[] tempBuffer = null; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => 1; + public override int ChannelCount => 1; private bool updateTime; - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive) { @@ -77,7 +73,7 @@ protected override void OnStart() } } [NodeCategory("Obsidian/Audio/Generators")] - public class SawtoothGenerator : ProxyVoidNode, IExecutionChangeListener + public class SawtoothGenerator : AudioGeneratorNode { [ChangeListener] [DefaultValueAttribute(440f)] @@ -96,96 +92,19 @@ public class SawtoothGenerator : ProxyVoidNode AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(SawtoothGeneratorProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(SawtoothGeneratorProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(SawtoothGeneratorProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - SawtoothGeneratorProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { SawtoothGeneratorProxy proxy = GetProxy(context); if (proxy == null) { return; } + base.Changed(context); proxy.Amplitude = Amplitude.Evaluate(context, 1f); proxy.Phase = Phase.Evaluate(context, 0f); proxy.Frequency = Frequency.Evaluate(context, 440f); } - protected override void ComputeOutputs(FrooxEngineContext context) - { - SawtoothGeneratorProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - private IOperation DoReset(FrooxEngineContext context) { SawtoothGeneratorProxy proxy = GetProxy(context); @@ -199,7 +118,6 @@ private IOperation DoReset(FrooxEngineContext context) public SawtoothGenerator() { - AudioOutput = new ObjectOutput(this); Reset = new Operation(this, 0); } } diff --git a/ProjectObsidian/ProtoFlux/Audio/SineGenerator.cs b/ProjectObsidian/ProtoFlux/Audio/SineGenerator.cs index c8ee0d4..5fa4759 100644 --- a/ProjectObsidian/ProtoFlux/Audio/SineGenerator.cs +++ b/ProjectObsidian/ProtoFlux/Audio/SineGenerator.cs @@ -10,7 +10,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class SineGeneratorProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class SineGeneratorProxy : AudioGeneratorNodeProxy { public float Frequency; @@ -22,15 +22,11 @@ public class SineGeneratorProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, private float[] tempBuffer = null; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => 1; + public override int ChannelCount => 1; private bool updateTime; - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive) { @@ -75,7 +71,7 @@ protected override void OnStart() } } [NodeCategory("Obsidian/Audio/Generators")] - public class SineGenerator : ProxyVoidNode, IExecutionChangeListener + public class SineGenerator : AudioGeneratorNode { [ChangeListener] [DefaultValueAttribute(440f)] @@ -94,96 +90,19 @@ public class SineGenerator : ProxyVoidNode AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(SineGeneratorProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(SineGeneratorProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(SineGeneratorProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - SineGeneratorProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { SineGeneratorProxy proxy = GetProxy(context); if (proxy == null) { return; } + base.Changed(context); proxy.Amplitude = Amplitude.Evaluate(context, 1f); proxy.Phase = Phase.Evaluate(context, 0f); proxy.Frequency = Frequency.Evaluate(context, 440f); } - protected override void ComputeOutputs(FrooxEngineContext context) - { - SineGeneratorProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - private IOperation DoReset(FrooxEngineContext context) { SineGeneratorProxy proxy = GetProxy(context); @@ -197,7 +116,6 @@ private IOperation DoReset(FrooxEngineContext context) public SineGenerator() { - AudioOutput = new ObjectOutput(this); Reset = new Operation(this, 0); } } diff --git a/ProjectObsidian/ProtoFlux/Audio/SineShapedRingModulatorNode.cs b/ProjectObsidian/ProtoFlux/Audio/SineShapedRingModulatorNode.cs index 1986e93..6d164b3 100644 --- a/ProjectObsidian/ProtoFlux/Audio/SineShapedRingModulatorNode.cs +++ b/ProjectObsidian/ProtoFlux/Audio/SineShapedRingModulatorNode.cs @@ -10,21 +10,13 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class SineShapedRingModulatorProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class SineShapedRingModulatorProxy : DualInputAudioGeneratorNodeProxy { - public IWorldAudioDataSource AudioInput; - - public IWorldAudioDataSource AudioInput2; - public float ModulationIndex; - public bool Active; - - public bool IsActive => Active; + public override int ChannelCount => MathX.Min(AudioInput?.ChannelCount ?? 0, AudioInput2?.ChannelCount ?? 0); - public int ChannelCount => MathX.Min(AudioInput?.ChannelCount ?? 0, AudioInput2?.ChannelCount ?? 0); - - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive || AudioInput == null || AudioInput2 == null) { @@ -43,110 +35,21 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio/Effects")] - public class SineShapedRingModulator : ProxyVoidNode, IExecutionChangeListener + public class SineShapedRingModulator : DualInputAudioGeneratorNode { - [ChangeListener] - public readonly ObjectInput AudioInput; - - [ChangeListener] - public readonly ObjectInput AudioInput2; - [ChangeListener] public readonly ValueInput ModulationIndex; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(SineShapedRingModulatorProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(SineShapedRingModulatorProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(SineShapedRingModulatorProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - SineShapedRingModulatorProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { + SineShapedRingModulatorProxy proxy = GetProxy(context); if (proxy == null) { return; } - proxy.AudioInput = AudioInput.Evaluate(context); - proxy.AudioInput2 = AudioInput2.Evaluate(context); + base.Changed(context); proxy.ModulationIndex = ModulationIndex.Evaluate(context); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - SineShapedRingModulatorProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public SineShapedRingModulator() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/SquareGenerator.cs b/ProjectObsidian/ProtoFlux/Audio/SquareGenerator.cs index b7dd8e4..d09f396 100644 --- a/ProjectObsidian/ProtoFlux/Audio/SquareGenerator.cs +++ b/ProjectObsidian/ProtoFlux/Audio/SquareGenerator.cs @@ -10,7 +10,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class SquareGeneratorProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class SquareGeneratorProxy : AudioGeneratorNodeProxy { public float Frequency; @@ -24,15 +24,11 @@ public class SquareGeneratorProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSourc private float[] tempBuffer = null; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => 1; + public override int ChannelCount => 1; private bool updateTime; - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive) { @@ -86,7 +82,7 @@ protected override void OnStart() } } [NodeCategory("Obsidian/Audio/Generators")] - public class SquareGenerator : ProxyVoidNode, IExecutionChangeListener + public class SquareGenerator : AudioGeneratorNode { [ChangeListener] [DefaultValueAttribute(440f)] @@ -109,97 +105,20 @@ public class SquareGenerator : ProxyVoidNode AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(SquareGeneratorProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(SquareGeneratorProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(SquareGeneratorProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - SquareGeneratorProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { SquareGeneratorProxy proxy = GetProxy(context); if (proxy == null) { return; } + base.Changed(context); proxy.Amplitude = Amplitude.Evaluate(context, 1f); proxy.Phase = Phase.Evaluate(context, 0f); proxy.Frequency = Frequency.Evaluate(context, 440f); proxy.PulseWidth = PulseWidth.Evaluate(context, 0.5f); } - protected override void ComputeOutputs(FrooxEngineContext context) - { - SquareGeneratorProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - private IOperation DoReset(FrooxEngineContext context) { SquareGeneratorProxy proxy = GetProxy(context); @@ -213,7 +132,6 @@ private IOperation DoReset(FrooxEngineContext context) public SquareGenerator() { - AudioOutput = new ObjectOutput(this); Reset = new Operation(this, 0); } } diff --git a/ProjectObsidian/ProtoFlux/Audio/StereoCombiner.cs b/ProjectObsidian/ProtoFlux/Audio/StereoCombiner.cs index ce12b91..30a8d2e 100644 --- a/ProjectObsidian/ProtoFlux/Audio/StereoCombiner.cs +++ b/ProjectObsidian/ProtoFlux/Audio/StereoCombiner.cs @@ -8,19 +8,15 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class StereoCombinerProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class StereoCombinerProxy : AudioGeneratorNodeProxy { public IWorldAudioDataSource Left; public IWorldAudioDataSource Right; - public bool Active; + public override int ChannelCount => 2; - public bool IsActive => Active; - - public int ChannelCount => 2; - - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive) { @@ -55,7 +51,7 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio")] - public class StereoCombiner : ProxyVoidNode, IExecutionChangeListener + public class StereoCombiner : AudioGeneratorNode { [ChangeListener] public readonly ObjectInput Left; @@ -63,98 +59,16 @@ public class StereoCombiner : ProxyVoidNode Right; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(StereoCombinerProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(StereoCombinerProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(StereoCombinerProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - StereoCombinerProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { StereoCombinerProxy proxy = GetProxy(context); if (proxy == null) { return; } + base.Changed(context); proxy.Left = Left.Evaluate(context); proxy.Right = Right.Evaluate(context); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - StereoCombinerProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public StereoCombiner() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/Surround51_Combiner.cs b/ProjectObsidian/ProtoFlux/Audio/Surround51_Combiner.cs index 1e18b71..be0f0e3 100644 --- a/ProjectObsidian/ProtoFlux/Audio/Surround51_Combiner.cs +++ b/ProjectObsidian/ProtoFlux/Audio/Surround51_Combiner.cs @@ -8,7 +8,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class Surround51_CombinerProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class Surround51_CombinerProxy : AudioGeneratorNodeProxy { public IWorldAudioDataSource LeftFront; @@ -22,13 +22,9 @@ public class Surround51_CombinerProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataS public IWorldAudioDataSource RightRear; - public bool Active; + public override int ChannelCount => 6; - public bool IsActive => Active; - - public int ChannelCount => 6; - - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive) { @@ -91,7 +87,7 @@ public void Read(Span buffer, AudioSimulator simulator) where S : unmanage } } [NodeCategory("Obsidian/Audio")] - public class Surround51_Combiner : ProxyVoidNode, IExecutionChangeListener + public class Surround51_Combiner : AudioGeneratorNode { [ChangeListener] public readonly ObjectInput LeftFront; @@ -111,85 +107,14 @@ public class Surround51_Combiner : ProxyVoidNode RightRear; - public readonly ObjectOutput AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(Surround51_CombinerProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(Surround51_CombinerProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(Surround51_CombinerProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - Surround51_CombinerProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { Surround51_CombinerProxy proxy = GetProxy(context); if (proxy == null) { return; } + base.Changed(context); proxy.LeftFront = LeftFront.Evaluate(context); proxy.RightFront = RightFront.Evaluate(context); proxy.Center = Center.Evaluate(context); @@ -197,16 +122,5 @@ public void Changed(FrooxEngineContext context) proxy.LeftRear = LeftRear.Evaluate(context); proxy.RightRear = RightRear.Evaluate(context); } - - protected override void ComputeOutputs(FrooxEngineContext context) - { - Surround51_CombinerProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - - public Surround51_Combiner() - { - AudioOutput = new ObjectOutput(this); - } } } \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/Audio/TriangleGenerator.cs b/ProjectObsidian/ProtoFlux/Audio/TriangleGenerator.cs index 220d1fe..7cb3655 100644 --- a/ProjectObsidian/ProtoFlux/Audio/TriangleGenerator.cs +++ b/ProjectObsidian/ProtoFlux/Audio/TriangleGenerator.cs @@ -10,7 +10,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Audio { - public class TriangleGeneratorProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSource, IWorldAudioDataSource + public class TriangleGeneratorProxy : AudioGeneratorNodeProxy { public float Frequency; @@ -22,15 +22,11 @@ public class TriangleGeneratorProxy : ProtoFluxEngineProxy, Awwdio.IAudioDataSou private float[] tempBuffer = null; - public bool Active; - - public bool IsActive => Active; - - public int ChannelCount => 1; + public override int ChannelCount => 1; private bool updateTime; - public void Read(Span buffer, AudioSimulator simulator) where S : unmanaged, IAudioSample + public override void Read(Span buffer, AudioSimulator simulator) { if (!IsActive) { @@ -82,7 +78,7 @@ protected override void OnStart() } } [NodeCategory("Obsidian/Audio/Generators")] - public class TriangleGenerator : ProxyVoidNode, IExecutionChangeListener + public class TriangleGenerator : AudioGeneratorNode { [ChangeListener] [DefaultValueAttribute(440f)] @@ -101,96 +97,19 @@ public class TriangleGenerator : ProxyVoidNode AudioOutput; - - private ObjectStore> _enabledChangedHandler; - - private ObjectStore _activeChangedHandler; - - public bool ValueListensToChanges { get; private set; } - - private bool ShouldListen(TriangleGeneratorProxy proxy) - { - if (proxy.Enabled) - { - return proxy.Slot.IsActive; - } - return false; - } - - protected override void ProxyAdded(TriangleGeneratorProxy proxy, FrooxEngineContext context) - { - base.ProxyAdded(proxy, context); - NodeContextPath path = context.CaptureContextPath(); - ProtoFluxNodeGroup group = context.Group; - context.GetEventDispatcher(out var dispatcher); - Action enabledHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - SlotEvent activeHandler = delegate - { - dispatcher.ScheduleEvent(path, delegate (FrooxEngineContext c) - { - UpdateListenerState(c); - }); - }; - proxy.EnabledField.Changed += enabledHandler; - proxy.Slot.ActiveChanged += activeHandler; - _enabledChangedHandler.Write(enabledHandler, context); - _activeChangedHandler.Write(activeHandler, context); - ValueListensToChanges = ShouldListen(proxy); - proxy.Active = ValueListensToChanges; - } - - protected override void ProxyRemoved(TriangleGeneratorProxy proxy, FrooxEngineContext context, bool inUseByAnotherInstance) - { - if (!inUseByAnotherInstance) - { - proxy.EnabledField.Changed -= _enabledChangedHandler.Read(context); - proxy.Slot.ActiveChanged -= _activeChangedHandler.Read(context); - _enabledChangedHandler.Clear(context); - _activeChangedHandler.Clear(context); - proxy.Active = false; - } - } - - protected void UpdateListenerState(FrooxEngineContext context) - { - TriangleGeneratorProxy proxy = GetProxy(context); - if (proxy != null) - { - bool shouldListen = ShouldListen(proxy); - if (shouldListen != ValueListensToChanges) - { - ValueListensToChanges = shouldListen; - context.Group.MarkChangeTrackingDirty(); - proxy.Active = shouldListen; - } - } - } - - public void Changed(FrooxEngineContext context) + public override void Changed(FrooxEngineContext context) { TriangleGeneratorProxy proxy = GetProxy(context); if (proxy == null) { return; } + base.Changed(context); proxy.Amplitude = Amplitude.Evaluate(context, 1f); proxy.Phase = Phase.Evaluate(context, 0f); proxy.Frequency = Frequency.Evaluate(context, 440f); } - protected override void ComputeOutputs(FrooxEngineContext context) - { - TriangleGeneratorProxy proxy = GetProxy(context); - AudioOutput.Write(proxy, context); - } - private IOperation DoReset(FrooxEngineContext context) { TriangleGeneratorProxy proxy = GetProxy(context); @@ -204,7 +123,6 @@ private IOperation DoReset(FrooxEngineContext context) public TriangleGenerator() { - AudioOutput = new ObjectOutput(this); Reset = new Operation(this, 0); } } diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAddValueToObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAddValueToObjectNode.cs index f658cd4..607de1b 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonAddValueToObjectNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonAddValueToObjectNode.cs @@ -12,8 +12,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; [NodeName("Add To Object")] [NodeCategory("Obsidian/Json")] -[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), - typeof(long), typeof(ulong), typeof(float), typeof(double))] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double))] public class JsonAddValueToObjectNode : ObjectFunctionNode where T : unmanaged { public readonly ObjectInput Input; diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToArrayNode.cs index c4b499c..4f9979e 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonAppendValueToArrayNode.cs @@ -12,8 +12,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; [NodeName("Append To Array")] [NodeCategory("Obsidian/Json")] -[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), - typeof(ulong), typeof(float), typeof(double))] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double))] public class JsonAppendValueToArrayNode : ObjectFunctionNode where T : unmanaged { public readonly ObjectInput Array; diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs index 5943a40..a85c3cf 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromArrayNode.cs @@ -9,8 +9,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; [NodeName("Get From Array")] [NodeCategory("Obsidian/Json")] -[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), - typeof(ulong), typeof(float), typeof(double))] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double))] public class JsonGetValueFromArrayNode : ValueFunctionNode where T : unmanaged { public readonly ObjectInput Input; diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs index 4d03085..682ca79 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonGetValueFromObjectNode.cs @@ -12,8 +12,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; [NodeName("Get From Object")] [NodeCategory("Obsidian/Json")] -[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), - typeof(ulong), typeof(float), typeof(double))] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double))] public class JsonGetValueFromObjectNode : ValueFunctionNode where T : unmanaged { public readonly ObjectInput Input; diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs index 35c89ab..b9550c0 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonInsertValueToArrayNode.cs @@ -12,8 +12,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; [NodeName("Insert To Array")] [NodeCategory("Obsidian/Json")] -[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), - typeof(long), typeof(ulong), typeof(float), typeof(double))] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double))] public class JsonInsertValueToArrayNode : ObjectFunctionNode where T : unmanaged { public readonly ObjectInput Array; diff --git a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs index bba5e0d..4a81ca4 100644 --- a/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs +++ b/ProjectObsidian/ProtoFlux/JSON/JsonQuickGetValueFromObjectNode.cs @@ -12,8 +12,7 @@ namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Json; [NodeName("Quick Get From Object")] [NodeCategory("Obsidian/Json")] -[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), - typeof(ulong), typeof(float), typeof(double))] +[GenericTypes(typeof(byte), typeof(sbyte), typeof(short), typeof(ushort), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double))] public class JsonQuickGetValueFromObjectNode : ValueFunctionNode where T : unmanaged { public readonly ObjectInput Input;