Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Button - Master Switch.nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<defaultvalue></defaultvalue>
<id>audio_group</id>
<description>The group that this button should be associated with</description>
<label>Audio Group</label>
<label>Group Id</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
Expand Down
2 changes: 1 addition & 1 deletion Button - Music Mute Toggle.nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<defaultvalue></defaultvalue>
<id>audio_group</id>
<description>The group that this button should be associated with</description>
<label>Audio Group</label>
<label>Group Id</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
Expand Down
4 changes: 2 additions & 2 deletions Button - Trigger.nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
<defaultvalue></defaultvalue>
<id>audio_group</id>
<description>The group that this button should be associated with</description>
<label>Audio Group</label>
<label>Group Id</label>
</scriptparameter>
<scriptparameter>
<type>string</type>
<defaultvalue></defaultvalue>
<id>audio_name</id>
<description>Name of the audio file that will be played when triggered</description>
<label>Audio File</label>
<label>Audio Id</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
Expand Down
2 changes: 1 addition & 1 deletion Cue Trigger - Emergency Stop.nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<defaultvalue>60</defaultvalue>
<id>audio_interval</id>
<description>Interval that this will be cued when activated.</description>
<label>Interval (Seconds) [Range 0.1 - inf]</label>
<label>Audio Interval (Seconds) [Range 0.1 - inf]</label>
</scriptparameter>
<scriptparameter>
<type>bool</type>
Expand Down
2 changes: 1 addition & 1 deletion Debugger.nl2sco
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<param allowrot="false"/>
<param allowscale="false"/>
<usercolor>
<label></label>
<label>.</label>
<index>0</index>
<defaultcolor r="1" g="1" b="1"/>
</usercolor>
Expand Down
39 changes: 39 additions & 0 deletions Emitter - Point.nl2sco
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<sceneobject>
<model path="models/PointEmitter.glb"/>
<description>Defines a cubic zone where a sound plays, ideal for indoor areas, enclosed spaces, or specific sections of a ride.</description>
<preview>thumbs/Cube.png</preview>
<param allowrot="false"/>
<param allowscale="false"/>
<usercolor>
<label>Color</label>
<index>0</index>
<defaultcolor r="1" g="1" b="1"/>
</usercolor>
<script>
<classpath></classpath>
<class>scripts.AudioEmitterPoint</class>
<sharedvm>true</sharedvm>
</script>
<scriptparameter>
<type>string</type>
<defaultvalue></defaultvalue>
<id>group_name</id>
<label>Group Name</label>
</scriptparameter>
<scriptparameter>
<type>double</type>
<defaultvalue>1</defaultvalue>
<id>audio_falloff</id>
<label>Fall Off</label>
</scriptparameter>
<scriptparameter>
<type>double</type>
<defaultvalue>1</defaultvalue>
<id>audio_distance</id>
<label>Constant Distance</label>
</scriptparameter>
<materialpath name="Material">materials/Emitters/Corner.nl2mat</materialpath>
</sceneobject>
</root>
Binary file added models/PointEmitter.glb
Binary file not shown.
49 changes: 41 additions & 8 deletions scripts/AudioController.nlvm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class AudioController extends Behaviour implements IReferenceable
private bool m_MutePrimaryTrack = false;
private bool m_IsEnabled = true;

private Dictionary m_AudioProperties = new Dictionary();
private String m_GroupName = "";

private float m_MuteGain = 0.05f;
Expand All @@ -34,7 +35,6 @@ public class AudioController extends Behaviour implements IReferenceable

return true;
}

public void Start()
{
Registry registry = Registry.GetInstance();
Expand All @@ -47,6 +47,7 @@ public class AudioController extends Behaviour implements IReferenceable
m_PrimaryAudioLoop = (SpatialSound)registry.GetReferenceFromName("scripts.SpatialSound", m_PrimaryAudioFile.GetName());
if(m_PrimaryAudioLoop == null)
Exception.Throw("Unable to find scripts.SpatialSound with name '" + GetStringParameter("primary_audio_name") + "'");
m_PrimaryAudioLoop.SetGain(0);
}

m_MuteGain = GetFloatParameter("audio_mute_gain");
Expand All @@ -65,19 +66,17 @@ public class AudioController extends Behaviour implements IReferenceable

registry.Register(this);

if(m_MutePrimaryTrack)
if(m_MutePrimaryTrack || m_PrimaryAudioLoop == null)
return;

for(int i = 0; i < m_GroupEmitters.length; ++i)
{
if(m_GroupEmitters[i] == null || m_PrimaryAudioLoop == null)
continue;

SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName());
sound.SetGain(m_PrimaryAudioFile.GetDefaultGain());
sound.SetPitch(m_PrimaryAudioFile.GetDefaultPitch());
sound.PlaySoundLooped();
}
AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_PrimaryAudioFile.GetDefaultGain());
}

private bool m_Debounce = false;
Expand All @@ -97,6 +96,7 @@ public class AudioController extends Behaviour implements IReferenceable
sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName());
sound.SetGain(0);
}
AddOrSetGain(m_PrimaryAudioLoop.GetName(), 0);

}
IEnumerator enumerator = m_Queue.GetEnumerator();
Expand All @@ -123,6 +123,7 @@ public class AudioController extends Behaviour implements IReferenceable
SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName());
sound.SetGainFaded(m_MutePrimaryTrack ? 0 : m_PrimaryAudioFile.GetDefaultGain(), 0.5f);
}
AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_MutePrimaryTrack ? 0 : m_PrimaryAudioFile.GetDefaultGain());
}
m_Debounce = true;
}
Expand Down Expand Up @@ -152,6 +153,7 @@ public class AudioController extends Behaviour implements IReferenceable
SpatialSound sound = m_GroupEmitters[i].SetCurrentSound(((AudioConfig)enumerator.Get()).SoundName);
sound.SetGain(0);
}
m_AudioProperties.Remove(((AudioConfig)enumerator.Get()).SoundName);
}


Expand All @@ -168,7 +170,7 @@ public class AudioController extends Behaviour implements IReferenceable
SpatialSound sound = m_GroupEmitters[j].SetCurrentSound(currentAudio.SoundName);
sound.SetGain(!isMutingLower ? currentAudio.FileReference.GetDefaultGain() : 0);
}

AddOrSetGain(currentAudio.SoundName, !isMutingLower ? currentAudio.FileReference.GetDefaultGain() : 0);
if(currentAudio.CanMuteLowerPriority)
isMutingLower = true;
}
Expand All @@ -181,23 +183,43 @@ public class AudioController extends Behaviour implements IReferenceable
if(m_MutePrimaryTrack)
{
sound.SetGainFaded(0, 0.5f);
AddOrSetGain(m_PrimaryAudioLoop.GetName(), 0);
return;
}
else
{
sound.SetGainFaded(m_PrimaryAudioFile.GetDefaultGain(), 0.5f);
AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_PrimaryAudioFile.GetDefaultGain());
}

if (isMutingLower)
{
sound.SetGainFaded(m_MuteGain, 0.5f);
AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_MuteGain);
}
else
{
sound.SetGainFaded(m_PrimaryAudioFile.GetDefaultGain(), 0.5f);
AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_PrimaryAudioFile.GetDefaultGain());
}
}
}
}

private void AddOrSetGain(String audioId, float gain)
{
if(m_AudioProperties.ContainsKey(audioId))
m_AudioProperties.Remove(audioId);
m_AudioProperties.Insert(audioId, new Float(gain));
}
public float GetAudioGain(String audioId)
{
Object val = m_AudioProperties.GetValue(audioId);
if(val == null)
return 0;
return ((Float)val).floatValue();
}


public void EnqueSound(AudioConfig properties)
{
Expand All @@ -215,7 +237,8 @@ public class AudioController extends Behaviour implements IReferenceable
spatialSound.SetPitch(properties.FileReference.GetDefaultPitch());
spatialSound.PlaySoundOnce();
}

// Cache current gain
AddOrSetGain(properties.SoundName, properties.FileReference.GetDefaultGain());
return;
}

Expand All @@ -235,6 +258,8 @@ public class AudioController extends Behaviour implements IReferenceable
spatialSound.Stop();
spatialSound.PlaySoundOnce();
}
// Cache current gain
AddOrSetGain(properties.SoundName, properties.FileReference.GetDefaultGain());
return;
}

Expand All @@ -248,11 +273,14 @@ public class AudioController extends Behaviour implements IReferenceable
SpatialSound spatialSound = m_GroupEmitters[i].SetCurrentSound(properties.SoundName);
spatialSound.PlaySoundOnce();
}
// Cache current gain
AddOrSetGain(properties.SoundName, properties.FileReference.GetDefaultGain());

// If they both equal the same property then we need to remove the old audio
while(properties.Priority == ((AudioConfig)enumerator.Get()).Priority)
{
DequeueSound(((AudioConfig)enumerator.Get()).SoundName);
m_AudioProperties.Remove(((AudioConfig)enumerator.Get()).SoundName);
if(!enumerator.MoveNext())
break;
}
Expand All @@ -270,6 +298,8 @@ public class AudioController extends Behaviour implements IReferenceable
SpatialSound spatialSound = m_GroupEmitters[i].SetCurrentSound(properties.SoundName);
spatialSound.PlaySoundOnce();
}
// Cache current gain
AddOrSetGain(properties.SoundName, properties.FileReference.GetDefaultGain());
}
}
public void DequeueSound(String soundName)
Expand All @@ -294,8 +324,9 @@ public class AudioController extends Behaviour implements IReferenceable
SpatialSound spatialSound = m_GroupEmitters[j].SetCurrentSound(sound.SoundName);
spatialSound.Stop();
}

//DequeueSound(sound.SoundName);
m_Queue.RemoveAt(i);
m_AudioProperties.Remove(sound.SoundName);
break;
}
}
Expand All @@ -313,6 +344,7 @@ public class AudioController extends Behaviour implements IReferenceable
if(m_IsEnabled)
sound.SetGainFaded(m_MutePrimaryTrack ? 0 : m_PrimaryAudioFile.GetDefaultGain(), 0.5f);
}
AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_MutePrimaryTrack ? 0 : m_PrimaryAudioFile.GetDefaultGain());
}
public void SetControllerOn(bool isEnabled)
{
Expand All @@ -325,6 +357,7 @@ public class AudioController extends Behaviour implements IReferenceable
sound = m_GroupEmitters[i].SetCurrentSound(m_PrimaryAudioLoop.GetName());
sound.SetGain(m_IsEnabled ? m_PrimaryAudioFile.GetDefaultGain() : 0);
}
AddOrSetGain(m_PrimaryAudioLoop.GetName(), m_IsEnabled ? m_PrimaryAudioFile.GetDefaultGain() : 0);
}

if(m_IsEnabled)
Expand Down
13 changes: 11 additions & 2 deletions scripts/AudioEmitter.nlvm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public abstract class AudioEmitter extends Behaviour implements IReferenceable
{
protected List m_AudioClips = new List();
protected SpatialSound m_ActiveSound = null;
private AudioController m_AudioGroup = null;

protected float m_FallOff = 1;
protected float m_Distance = 1;
Expand Down Expand Up @@ -34,7 +35,7 @@ public abstract class AudioEmitter extends Behaviour implements IReferenceable
{
return m_ActiveSound;
}
public final SpatialSound SetCurrentSound(String name)
public SpatialSound SetCurrentSound(String name)
{
//Debug.Print("Setting sound " + name);
// Try find the sound in the current emitter cache
Expand Down Expand Up @@ -65,7 +66,7 @@ public abstract class AudioEmitter extends Behaviour implements IReferenceable
//m_ActiveSound.SetPosition(GetPosition());
m_ActiveSound.SetConstantDistance(m_Distance);
m_ActiveSound.SetFalloffFactor(m_FallOff);
m_ActiveSound.SetPosition(GetPosition());
//m_ActiveSound.SetPosition(GetPosition());
//m_ActiveSound.SetShouldUseDoppler(false);

return m_ActiveSound;
Expand All @@ -76,6 +77,14 @@ public abstract class AudioEmitter extends Behaviour implements IReferenceable
return m_AudioClips;
}

public AudioController GetAudioController()
{
if(m_AudioGroup == null)
m_AudioGroup = (AudioController)Registry.GetInstance().GetReferenceFromName("scripts.AudioController", GetStringParameter("group_name"));
return m_AudioGroup;
}



// IReferenceable
public String GetType()
Expand Down
5 changes: 1 addition & 4 deletions scripts/AudioEmitterCar.nlvm
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public class AudioEmitterCar extends AudioEmitter

public bool Awake()
{
super.Awake();

m_Coaster = GetCoasterParameter("audio_coaster", false);
if(m_Coaster == null)
{
Expand All @@ -41,8 +39,7 @@ public class AudioEmitterCar extends AudioEmitter
Debug.Warn("Emitter - Car | The car index '" + m_CarIndex + "' is invalid for coaster '" + m_Coaster.getName() + "', must be <= " + m_Train.getCarCount());
return false;
}

return true;
return super.Awake();
}

public void Update(float tick)
Expand Down
11 changes: 11 additions & 0 deletions scripts/AudioEmitterPoint.nlvm
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package scripts;

public class AudioEmitterPoint extends AudioEmitter
{
public SpatialSound SetCurrentSound(String name)
{
SpatialSound sound = super.SetCurrentSound(name);
m_ActiveSound.SetPosition(GetPosition());
return sound;
}
}
Loading
Loading