/// <summary> /// Updates the form content. Warning: Creates garbage - Not any more I hope - Dennis /// </summary> private void UpdateContent() { var soundSources = Viewer.SoundProcess.SoundSources; activeSoundList.BeginUpdate(); inactiveSoundList.BeginUpdate(); for (int i = 0; i < activeSoundList.Nodes.Count; i++) { activeSoundList.Nodes[i].Nodes.Clear(); } for (int i = 0; i < inactiveSoundList.Nodes.Count; i++) { inactiveSoundList.Nodes[i].Nodes.Clear(); } lock (Viewer.SoundProcess.SoundSources) { foreach (var src in soundSources.Values) { foreach (var ssb in src) { if (ssb is SoundSource) { AddToForm((SoundSource)ssb); } else if (ssb is TrackSoundSource) { var ts = (TrackSoundSource)ssb; if (ts._activeInSource != null) { AddToForm(ts._activeInSource); } if (ts._activeOutSource != null) { AddToForm(ts._activeOutSource); } } } } CleanUp(activeSoundList.Nodes); CleanUp(inactiveSoundList.Nodes); activeSoundList.EndUpdate(); inactiveSoundList.EndUpdate(); // Fill selected node's data if (activeSoundList.SelectedNode != lastActSelectedNode) { selectedNode = activeSoundList.SelectedNode; lastActSelectedNode = activeSoundList.SelectedNode; inactiveSoundList.SelectedNode = null; lastInActSelectedNode = null; } else if (inactiveSoundList.SelectedNode != lastInActSelectedNode) { selectedNode = inactiveSoundList.SelectedNode; lastInActSelectedNode = inactiveSoundList.SelectedNode; activeSoundList.SelectedNode = null; lastActSelectedNode = null; } if (selectedNode != null && selectedNode.Tag is SoundSource && (SoundSource)selectedNode.Tag != null) { selectedSoundSource = (SoundSource)selectedNode.Tag; int soundSourceID = -1; int i = -1; if (selectedSoundSource.SoundStreams.Count > 0) { while (++i < selectedSoundSource.SoundStreams.Count) { soundSourceID = selectedSoundSource.SoundStreams[i].ALSoundSource.SoundSourceID; if (soundSourceID != -1) { break; } } } if (selectedSoundSource.WorldLocation != WorldLocation.None && selectedSoundSource.SoundStreams.Count > 0) { //Source distance: distance.Text = Math.Sqrt(selectedSoundSource.DistanceSquared).ToString("F1"); //Stream distance: //float[] pos = new float[3]; //OpenAL.alGetSource3f(soundSourceID, OpenAL.AL_POSITION, out pos[0], out pos[1], out pos[2]); //float[] lpos = new float[3]; //OpenAL.alGetListener3f(OpenAL.AL_POSITION, out lpos[0], out lpos[1], out lpos[2]); //for (var j = 0; j < 3; j++) // pos[j] -= lpos[j]; //distance.Text = Math.Sqrt(pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2]).ToString("F1"); } else { distance.Text = "-"; } int relative; OpenAL.GetSourcei(soundSourceID, OpenAL.AL_SOURCE_RELATIVE, out relative); sound3D.Checked = relative == OpenAL.AL_FALSE; if (selectedSoundSource.Car != null) { speed.Text = Math.Abs(selectedSoundSource.Car.SpeedMpS).ToString("F1"); var Variable1 = selectedSoundSource.Car.Variable1; var Variable2 = selectedSoundSource.Car.Variable2; var Variable3 = selectedSoundSource.Car.Variable3; if (selectedSoundSource.Car is MSTSSteamLocomotive) { Variable1 /= 100f; Variable2 /= 100f; Variable3 /= 100f; } if (selectedSoundSource.Car is MSTSElectricLocomotive) { Variable1 /= 100f; Variable2 /= 100f; } variable1.Text = Variable1.ToString("0.#%"); variable2.Text = Variable2.ToString("0.#%"); variable3.Text = Variable3.ToString("0.#%"); } else { speed.Text = "-"; variable1.Text = "-"; variable2.Text = "-"; variable3.Text = "-"; } float gain; OpenAL.GetSourcef(soundSourceID, OpenAL.AL_GAIN, out gain); smsVolume.Text = gain.ToString("0.#%"); } else { distance.Text = "-"; speed.Text = "-"; variable1.Text = "-"; variable2.Text = "-"; variable3.Text = "-"; smsVolume.Text = "-"; activeSoundList.SelectedNode = null; inactiveSoundList.SelectedNode = null; } waves.Text = SoundItem.AllPieces.Count.ToString(); alSources.Text = ALSoundSource.ActiveCount.ToString(); } }