{"TotalCount":27,"Files":[{"Ident":"carsonk.sfxr","Path":"UnitTests/UnitTest.cs","FileName":"UnitTest.cs","PackageType":"library","CodeKind":"UnitTest","AssetVersionId":55752,"IsPrivate":false,"Code":"global using Microsoft.VisualStudio.TestTools.UnitTesting;\r\n\r\n[TestClass]\r\npublic class TestInit\r\n{\r\n\t[AssemblyInitialize]\r\n\tpublic static void ClassInitialize( TestContext context )\r\n\t{\r\n\t\tSandbox.Application.InitUnitTest();\r\n\t}\r\n}\r\n"},{"Ident":"carsonk.sfxr","Path":"Code/SFXRComponent.cs","FileName":"SFXRComponent.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":55752,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing System.IO;\r\nusing System.Linq;\r\nusing Sandbox;\r\n\r\nnamespace SFXR;\r\n\r\n\r\n[Title( \u0022SFXR Component\u0022 )]\r\n[Category( \u0022SFXR\u0022 )]\r\n[Icon( \u0022volume_up\u0022 )]\r\npublic sealed class SFXRComponent : Component\r\n{\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The base Waveform\r\n\t/// (Default: Square)\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Sound\u0022 )]\r\n\tpublic Waveform Waveform { get; set; } = Waveform.Square;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The sample rate of the sound\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Sound\u0022 )]\r\n\tpublic SampleRate SampleRate { get; set; } = SampleRate.Hz44100;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The bit depth of the sound\r\n\t/// \u003C/summary\u003E\r\n\t// [Property, Group( \u0022Sound\u0022 )]\r\n\tpublic BitDepth BitDepth { get; set; } = BitDepth.Bit16;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The length of the sound in seconds\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Sound\u0022 ), Range( 0f, 20f, 0.01f )]\r\n\tpublic float Length { get; set; } = 0.5f;\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The volume of the sound\r\n\t/// (Default: 0.5)\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Sound\u0022 ), Range( 0f, 1f, 0.01f )]\r\n\tpublic float MasterVolume { get; set; } = 0.5f;\r\n\r\n\t[Property, Group( \u0022Frequency\u0022 ), Range( 0, 3000f, 1f )]\r\n\tfloat StartFrequency\r\n\t{\r\n\t\tget =\u003E Frequency.Start;\r\n\t\tset =\u003E Frequency.Start = value;\r\n\t}\r\n\r\n\t[Property, Group( \u0022Frequency\u0022 ), Range( -3000f, 3000f, 1f )]\r\n\tfloat Slide\r\n\t{\r\n\t\tget =\u003E Frequency.Slide;\r\n\t\tset =\u003E Frequency.Slide = value;\r\n\t}\r\n\r\n\t[Property, Group( \u0022Frequency\u0022 ), Range( -3000f, 3000f, 1f )]\r\n\tfloat SlideDelta\r\n\t{\r\n\t\tget =\u003E Frequency.DeltaSlide;\r\n\t\tset =\u003E Frequency.DeltaSlide = value;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// The random seed\r\n\t/// \u003C/summary\u003E\r\n\t[Property, Group( \u0022Controls\u0022 )]\r\n\tpublic long Seed { get; set; } = 0;\r\n\r\n\t[Property, Group( \u0022Controls\u0022 )]\r\n\tpublic SFXRControls Controls { get; set; } = new SFXRControls();\r\n\r\n\tpublic SFXRFrequency Frequency { get; set; } = new SFXRFrequency();\r\n\tRandom _random = new Random();\r\n\r\n\tList\u003CSFXRNote\u003E NotesPlaying = new();\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Plays the sound defined by the component\r\n\t/// \u003C/summary\u003E\r\n\t/// \u003Creturns\u003EThe sound handle of the sound. This can be used to change position, pitch, ect\u003C/returns\u003E\r\n\tpublic SoundHandle PlaySound()\r\n\t{\r\n\t\tvar sfx = Generate( (int)(Length * (int)SampleRate) );\r\n\t\tvar handle = sfx.Play();\r\n\t\t// DestroyStream(sfx, Length);\r\n\t\treturn handle;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Plays the sound defined by the component (Via a frequency trigger. This will play indefinitely until released)\r\n\t/// \u003C/summary\u003E\r\n\t/// \u003Cparam name=\u0022frequency\u0022\u003EThe frequency of the sound\u003C/param\u003E\r\n\t/// \u003Cparam name=\u0022volume\u0022\u003EThe volume of the trigger \u003C/param\u003E\r\n\tpublic void TriggerNotePress( float frequency, float volume = 1f )\r\n\t{\r\n\t\tforeach ( var note in NotesPlaying.Where( x =\u003E x.Frequency == frequency ) )\r\n\t\t{\r\n\t\t\tnote.Release();\r\n\t\t}\r\n\r\n\t\tvar newNote = new SFXRNote( this, frequency, volume );\r\n\t\tnewNote.Trigger();\r\n\t\tNotesPlaying.Add( newNote );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Releases a note playing at the given frequency\r\n\t/// \u003C/summary\u003E\r\n\t/// \u003Cparam name=\u0022frequency\u0022\u003EThe frequency of the sound\u003C/param\u003E\r\n\tpublic void TriggerNoteRelease( float frequency )\r\n\t{\r\n\t\tforeach ( var note in NotesPlaying.Where( x =\u003E x.Frequency == frequency ) )\r\n\t\t{\r\n\t\t\tnote.Release();\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Releases all notes playing\r\n\t/// \u003C/summary\u003E\r\n\tpublic void TriggerReleaseAll()\r\n\t{\r\n\t\tforeach ( var note in NotesPlaying )\r\n\t\t{\r\n\t\t\tnote.Release();\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Generates a sound stream from the component\r\n\t/// \u003C/summary\u003E\r\n\t/// \u003Cparam name=\u0022sampleCount\u0022\u003EHow many samples the stream should be filled with\u003C/param\u003E\r\n\t/// \u003Creturns\u003E\u003C/returns\u003E\r\n\tpublic SoundStream Generate( int sampleCount )\r\n\t{\r\n\t\tList\u003CSFXREffect\u003E effects = new();\r\n\r\n\t\tforeach ( var component in GameObject.Components.GetAll() )\r\n\t\t{\r\n\t\t\tif ( component is not SFXREffect effect || !effect.Enabled ) continue;\r\n\t\t\teffects.Add( effect );\r\n\t\t}\r\n\r\n\t\treturn Generate( sampleCount, effects );\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Generates a sound stream from the component with the given effects\r\n\t/// \u003C/summary\u003E\r\n\t/// \u003Cparam name=\u0022sampleCount\u0022\u003EThe number of samples\u003C/param\u003E\r\n\t/// \u003Cparam name=\u0022effects\u0022\u003EA list of the effects to apply\u003C/param\u003E\r\n\t/// \u003Creturns\u003E\u003C/returns\u003E\r\n\tpublic SoundStream Generate( int sampleCount, List\u003CSFXREffect\u003E effects )\r\n\t{\r\n\t\tshort[] samples = new short[sampleCount];\r\n\r\n\t\tfloat t = 0;\r\n\t\tfor ( int i = 0; i \u003C sampleCount; i\u002B\u002B )\r\n\t\t{\r\n\t\t\tt \u002B= 1f / (int)SampleRate;\r\n\t\t\tshort sampleValue = SFXR.GetWaveformSample( Waveform, t, Frequency.GetFrequency( t ) );\r\n\r\n\t\t\tsampleValue = (short)((float)sampleValue * MasterVolume);\r\n\r\n\t\t\tsamples[i] = sampleValue;\r\n\t\t}\r\n\r\n\t\tforeach ( var effect in effects )\r\n\t\t{\r\n\t\t\tif ( !effect.Enabled ) continue;\r\n\t\t\tsamples = effect.Apply( samples, this );\r\n\t\t}\r\n\r\n\t\tvar stream = new SoundStream( (int)SampleRate );\r\n\t\tstream.WriteData( samples );\r\n\r\n\t\treturn stream;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Randomizes the component\u0027s parameters\r\n\t/// \u003C/summary\u003E\r\n\tpublic void Randomize()\r\n\t{\r\n\t\tif ( Seed != 0 ) _random = new Random( (int)Seed );\r\n\r\n\t\tvar waveform = Waveform;\r\n\t\tResetParameters();\r\n\t\tWaveform = waveform;\r\n\r\n\t\tFrequency.Start = _random.Next( 10, 3000 );\r\n\t\tif ( _random.Next( 2 ) == 0 ) Frequency.Slide = _random.Next( -3000, 3000 );\r\n\t\tif ( Frequency.Start \u003E 2000 \u0026\u0026 Frequency.Slide \u003E 200 ) Frequency.Slide = -Frequency.Slide;\r\n\t\telse if ( Frequency.Start \u003C 400 \u0026\u0026 Frequency.Slide \u003C -50 ) Frequency.Slide = -Frequency.Slide;\r\n\t\tif ( _random.Next( 2 ) == 0 ) Frequency.DeltaSlide = _random.Next( -3000, 3000 );\r\n\r\n\t\tSanitizeParameters();\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Mutates the component\u0027s parameters slightly\r\n\t/// \u003C/summary\u003E\r\n\tpublic void Mutate( float mutation = 0.05f )\r\n\t{\r\n\t\tif ( Seed != 0 ) _random = new Random( (int)Seed );\r\n\r\n\t\tFrequency.Start \u002B= _random.Float( -mutation, mutation ) * 1000;\r\n\t\tif ( Frequency.Start \u003E 2000 \u0026\u0026 Frequency.Slide \u003E 200 ) Frequency.Slide = -Frequency.Slide;\r\n\t\telse if ( Frequency.Start \u003C 400 \u0026\u0026 Frequency.Slide \u003C -50 ) Frequency.Slide = -Frequency.Slide;\r\n\t\tFrequency.Slide \u002B= _random.Float( -mutation, mutation ) * 1000;\r\n\t\tFrequency.DeltaSlide \u002B= _random.Float( -mutation, mutation ) * 1000;\r\n\t\tif ( Frequency.Slide \u003C -3000 ) Frequency.Slide = -3000;\r\n\t\tif ( Frequency.Slide \u003E 3000 ) Frequency.Slide = 3000;\r\n\r\n\t\tSanitizeParameters();\r\n\t}\r\n\r\n\r\n\tpublic void RandomizePickup()\r\n\t{\r\n\t\tif ( Seed != 0 ) _random = new Random( (int)Seed );\r\n\t\tResetParameters();\r\n\t\tforeach ( var component in GameObject.Components.GetAll() )\r\n\t\t{\r\n\t\t\tif ( component is not SFXREffect effect ) continue;\r\n\t\t\teffect.Enabled = false;\r\n\t\t}\r\n\t\tvar envelope = Components.GetOrCreate\u003CSFXREnvelope\u003E();\r\n\r\n\t\tWaveform = (Waveform)_random.Int( 0, 2 );\r\n\r\n\t\tFrequency.Start = _random.Float( 0.4f, 0.9f ) * 3000;\r\n\r\n\t\tenvelope.Enabled = true;\r\n\t\tenvelope.Attack = 0;\r\n\t\tenvelope.Decay = _random.Float( 0.1f, 0.3f );\r\n\t\tenvelope.Sustain = _random.Float( 0f, 0.1f );\r\n\t\tenvelope.Release = _random.Float( 0.1f, 0.3f );\r\n\r\n\t\tLength = envelope.Attack \u002B envelope.Sustain \u002B envelope.Decay \u002B envelope.Release;\r\n\r\n\t}\r\n\r\n\tpublic void RandomizeLaser()\r\n\t{\r\n\t\tif ( Seed != 0 ) _random = new Random( (int)Seed );\r\n\t\tResetParameters();\r\n\t\tforeach ( var component in GameObject.Components.GetAll() )\r\n\t\t{\r\n\t\t\tif ( component is not SFXREffect effect ) continue;\r\n\t\t\teffect.Enabled = false;\r\n\t\t}\r\n\t\tvar envelope = Components.GetOrCreate\u003CSFXREnvelope\u003E();\r\n\t\tvar highpass = Components.GetOrCreate\u003CSFXRHighPass\u003E();\r\n\r\n\t\tWaveform = (Waveform)_random.Int( 0, 2 );\r\n\t\tif ( Waveform == Waveform.Sine \u0026\u0026 _random.Next( 2 ) == 0 ) Waveform = (Waveform)_random.Int( 0, 1 );\r\n\r\n\t\tFrequency.Start = _random.Float( 0.6f, 0.75f ) * 3000;\r\n\t\tFrequency.Slide = _random.Float( -0.25f, -0.15f ) * 3000;\r\n\t\tenvelope.Enabled = true;\r\n\t\tenvelope.Attack = 0;\r\n\t\tenvelope.Decay = _random.Float( 0f, 0.4f );\r\n\t\tenvelope.Sustain = _random.Float( 0.1f, 0.3f );\r\n\t\tenvelope.Release = _random.Float( 0.25f, 0.3f );\r\n\t\tLength = envelope.Attack \u002B envelope.Sustain \u002B envelope.Decay \u002B envelope.Release;\r\n\r\n\t\tif ( _random.Next( 2 ) == 0 )\r\n\t\t{\r\n\t\t\thighpass.Enabled = true;\r\n\t\t\thighpass.Cutoff = _random.Float( 0f, 0.3f );\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void RandomizeExplosion()\r\n\t{\r\n\r\n\t\tif ( Seed != 0 ) _random = new Random( (int)Seed );\r\n\t\tResetParameters();\r\n\t\tforeach ( var component in GameObject.Components.GetAll() )\r\n\t\t{\r\n\t\t\tif ( component is not SFXREffect effect ) continue;\r\n\t\t\teffect.Enabled = false;\r\n\t\t}\r\n\t\tvar envelope = Components.GetOrCreate\u003CSFXREnvelope\u003E();\r\n\t\tvar vibrato = Components.GetOrCreate\u003CSFXRVibrato\u003E();\r\n\r\n\t\tWaveform = Waveform.Noise;\r\n\r\n\t\tif ( _random.Next( 2 ) == 0 )\r\n\t\t{\r\n\t\t\tFrequency.Start = _random.Float( 0.025f, 0.15f ) * 3000;\r\n\t\t\tFrequency.Slide = _random.Float( -0.1f, -0.01f ) * 3000;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tFrequency.Start = _random.Float( 0.1f, 0.2f ) * 3000;\r\n\t\t\tFrequency.Slide = _random.Float( -0.6f, 0.6f ) * 3000;\r\n\t\t}\r\n\r\n\t\tif ( _random.Next( 4 ) == 0 ) Frequency.Slide = 0;\r\n\r\n\t\tenvelope.Enabled = true;\r\n\t\tenvelope.Attack = 0;\r\n\t\tenvelope.Sustain = _random.Float( 0.1f, 0.4f );\r\n\t\tenvelope.Release = _random.Float( 0.1f, 0.3f );\r\n\t\tLength = envelope.Attack \u002B envelope.Sustain \u002B envelope.Decay \u002B envelope.Release;\r\n\r\n\r\n\t\tif ( _random.Next( 2 ) == 0 )\r\n\t\t{\r\n\t\t\tvibrato.Enabled = true;\r\n\t\t\tvibrato.Depth = _random.Float( 0f, 0.7f );\r\n\t\t\tvibrato.Speed = _random.Float( 0f, 60f );\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tvibrato.Enabled = false;\r\n\t\t}\r\n\r\n\t\tif ( -Frequency.Slide \u003E Frequency.Start )\r\n\t\t{\r\n\t\t\tFrequency.Slide = -Frequency.Start;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void RandomizePowerup()\r\n\t{\r\n\t\tif ( Seed != 0 ) _random = new Random( (int)Seed );\r\n\t\tResetParameters();\r\n\t\tforeach ( var component in GameObject.Components.GetAll() )\r\n\t\t{\r\n\t\t\tif ( component is not SFXREffect effect ) continue;\r\n\t\t\teffect.Enabled = false;\r\n\t\t}\r\n\t\tvar envelope = Components.GetOrCreate\u003CSFXREnvelope\u003E();\r\n\t\tvar vibrato = Components.GetOrCreate\u003CSFXRVibrato\u003E();\r\n\r\n\t\tif ( _random.Next( 2 ) == 0 )\r\n\t\t{\r\n\t\t\tWaveform = Waveform.Sawtooth;\r\n\t\t}\r\n\r\n\t\tif ( _random.Next( 2 ) == 0 )\r\n\t\t{\r\n\t\t\tFrequency.Start = _random.Float( 0.2f, 0.5f ) * 3000;\r\n\t\t\tFrequency.Slide = _random.Float( 0.1f, 0.5f ) * 3000;\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tFrequency.Start = _random.Float( 0.25f, 0.5f ) * 3000;\r\n\t\t\tFrequency.Slide = _random.Float( 0.05f, 0.25f ) * 3000;\r\n\t\t\tif ( _random.Next( 2 ) == 0 )\r\n\t\t\t{\r\n\t\t\t\tvibrato.Enabled = true;\r\n\t\t\t\tvibrato.Depth = _random.Float( 0, 0.7f );\r\n\t\t\t\tvibrato.Speed = _random.Float( 0, 60f );\r\n\t\t\t}\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tvibrato.Enabled = false;\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tif ( -Frequency.Slide \u003E Frequency.Start )\r\n\t\t{\r\n\t\t\tFrequency.Slide = -Frequency.Start;\r\n\t\t}\r\n\r\n\t\tenvelope.Enabled = true;\r\n\t\tenvelope.Attack = 0;\r\n\t\tenvelope.Sustain = _random.Float( 0f, 0.4f );\r\n\t\tenvelope.Release = _random.Float( 0.1f, 0.5f );\r\n\t\tLength = envelope.Attack \u002B envelope.Sustain \u002B envelope.Decay \u002B envelope.Release;\r\n\t}\r\n\r\n\tpublic void RandomizeHit()\r\n\t{\r\n\t\tif ( Seed != 0 ) _random = new Random( (int)Seed );\r\n\t\tResetParameters();\r\n\t\tforeach ( var component in GameObject.Components.GetAll() )\r\n\t\t{\r\n\t\t\tif ( component is not SFXREffect effect ) continue;\r\n\t\t\teffect.Enabled = false;\r\n\t\t}\r\n\t\tvar envelope = Components.GetOrCreate\u003CSFXREnvelope\u003E();\r\n\t\tvar highpass = Components.GetOrCreate\u003CSFXRHighPass\u003E();\r\n\r\n\t\tWaveform = (Waveform)_random.Int( 0, 3 );\r\n\t\tif ( Waveform == Waveform.Sine )\r\n\t\t{\r\n\t\t\tWaveform = Waveform.Noise;\r\n\t\t}\r\n\r\n\t\tFrequency.Start = _random.Float( 0.1f, 0.5f ) * 3000;\r\n\t\tFrequency.Slide = _random.Float( -0.7f, -0.3f ) * 3000;\r\n\r\n\t\tif ( -Frequency.Slide \u003E Frequency.Start )\r\n\t\t{\r\n\t\t\tFrequency.Slide = -Frequency.Start;\r\n\t\t}\r\n\r\n\t\tenvelope.Enabled = true;\r\n\t\tenvelope.Attack = 0;\r\n\t\tenvelope.Decay = 0;\r\n\t\tenvelope.Sustain = _random.Float( 0.025f, 0.1f );\r\n\t\tenvelope.Release = _random.Float( 0.1f, 0.3f );\r\n\t\tLength = envelope.Attack \u002B envelope.Sustain \u002B envelope.Decay \u002B envelope.Release;\r\n\r\n\t\tif ( _random.Next( 2 ) == 0 )\r\n\t\t{\r\n\t\t\thighpass.Enabled = true;\r\n\t\t\thighpass.Cutoff = _random.Float( 0f, 0.3f );\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\thighpass.Enabled = false;\r\n\t\t}\r\n\t}\r\n\r\n\tpublic void RandomizeJump()\r\n\t{\r\n\t\tif ( Seed != 0 ) _random = new Random( (int)Seed );\r\n\t\tResetParameters();\r\n\t\tforeach ( var component in GameObject.Components.GetAll() )\r\n\t\t{\r\n\t\t\tif ( component is not SFXREffect effect ) continue;\r\n\t\t\teffect.Enabled = false;\r\n\t\t}\r\n\t\tvar envelope = Components.GetOrCreate\u003CSFXREnvelope\u003E();\r\n\r\n\t\tWaveform = Waveform.Square;\r\n\r\n\t\tFrequency.Start = _random.Float( 0.3f, 0.6f ) * 3000;\r\n\t\tFrequency.Slide = _random.Float( 0.1f, 0.3f ) * 3000;\r\n\r\n\t\tif ( -Frequency.Slide \u003E Frequency.Start )\r\n\t\t{\r\n\t\t\tFrequency.Slide = -Frequency.Start;\r\n\t\t}\r\n\r\n\t\tenvelope.Enabled = true;\r\n\t\tenvelope.Attack = 0;\r\n\t\tenvelope.Sustain = _random.Float( 0.1f, 0.4f );\r\n\t\tenvelope.Release = _random.Float( 0.1f, 0.3f );\r\n\t\tLength = envelope.Attack \u002B envelope.Sustain \u002B envelope.Decay \u002B envelope.Release;\r\n\t}\r\n\r\n\tpublic void RandomizeBlip()\r\n\t{\r\n\t\tif ( Seed != 0 ) _random = new Random( (int)Seed );\r\n\t\tResetParameters();\r\n\t\tforeach ( var component in GameObject.Components.GetAll() )\r\n\t\t{\r\n\t\t\tif ( component is not SFXREffect effect ) continue;\r\n\t\t\teffect.Enabled = false;\r\n\t\t}\r\n\t\tvar envelope = Components.GetOrCreate\u003CSFXREnvelope\u003E();\r\n\r\n\t\tWaveform = Waveform.Square;\r\n\r\n\t\tFrequency.Start = _random.Float( 0.2f, 0.6f ) * 3000;\r\n\r\n\t\tenvelope.Enabled = true;\r\n\t\tenvelope.Attack = 0;\r\n\t\tenvelope.Decay = _random.Float( 0.1f, 0.2f );\r\n\t\tenvelope.Sustain = _random.Float( 0.025f, 0.1f );\r\n\t\tenvelope.Release = _random.Float( 0.1f, 0.3f );\r\n\t\tLength = envelope.Attack \u002B envelope.Sustain \u002B envelope.Decay \u002B envelope.Release;\r\n\t}\r\n\r\n\r\n\tpublic void ResetParameters()\r\n\t{\r\n\t\tWaveform = Waveform.Square;\r\n\t\tSampleRate = SampleRate.Hz44100;\r\n\t\tBitDepth = BitDepth.Bit16;\r\n\t\tLength = 0.5f;\r\n\t\tMasterVolume = 0.5f;\r\n\t\tFrequency = new SFXRFrequency();\r\n\t\tControls = new SFXRControls();\r\n\t}\r\n\r\n\tvoid SanitizeParameters()\r\n\t{\r\n\r\n\t}\r\n\r\n\tprotected override void OnUpdate()\r\n\t{\r\n\t\tforeach ( var note in NotesPlaying )\r\n\t\t{\r\n\t\t\tnote.Update();\r\n\r\n\t\t\t// if (!note.IsPlaying)\r\n\t\t\t// {\r\n\t\t\t// \tnote.DestroyStreams();\r\n\t\t\t// }\r\n\t\t}\r\n\r\n\t\tNotesPlaying.RemoveAll( x =\u003E !x.IsPlaying );\r\n\t}\r\n}\r\n"},{"Ident":"carsonk.sfxr","Path":"Editor/SFXRNotesListControlWidget.cs","FileName":"SFXRNotesListControlWidget.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":55752,"IsPrivate":false,"Code":"using Editor;\r\nusing Sandbox;\r\nusing Sandbox.Helpers;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\n\r\nnamespace SFXR.Editor;\r\n\r\n[CustomEditor( typeof( List\u003CSFXRSequencer.Note\u003E ) )]\r\npublic class SFXRNotesListControlWidget : ControlWidget\r\n{\r\n    private SerializedCollection Collection;\r\n\r\n    private Layout Content;\r\n\r\n    private Button addButton;\r\n\r\n    public override bool SupportsMultiEdit =\u003E false;\r\n\r\n    SFXRSequencer Sequencer;\r\n\r\n    public SFXRNotesListControlWidget( SerializedProperty property )\r\n        : base( property )\r\n    {\r\n        SetSizeMode( SizeMode.Ignore, SizeMode.Ignore );\r\n\r\n        base.Layout = Layout.Column();\r\n        base.Layout.Spacing = 2f;\r\n        if ( property.TryGetAsObject( out var obj ) \u0026\u0026 obj is SerializedCollection collection )\r\n        {\r\n            if ( property.Parent.Targets.First() is SFXRSequencer sequencer )\r\n            {\r\n                Sequencer = sequencer;\r\n            }\r\n\r\n            Collection = collection;\r\n            Collection.OnEntryAdded = Rebuild;\r\n            Collection.OnEntryRemoved = Rebuild;\r\n            Content = Layout.Column();\r\n            base.Layout.Add( Content );\r\n            Layout layout = base.Layout.AddRow();\r\n            layout.Margin = 8;\r\n            layout.AddStretchCell();\r\n            addButton = layout.Add( new Button( \u0022Add Note\u0022 )\r\n            {\r\n                ToolTip = \u0022Add new note\u0022,\r\n            } );\r\n            addButton.MinimumWidth = 200;\r\n            addButton.Clicked = () =\u003E AddEntry();\r\n            layout.AddStretchCell();\r\n            Rebuild();\r\n        }\r\n    }\r\n\r\n    public void Rebuild()\r\n    {\r\n        Content.Clear( deleteWidgets: true );\r\n        Content.Margin = 0f;\r\n        Layout layout = Layout.Column();\r\n        layout.Spacing = 2f;\r\n        int num = 0;\r\n        int count = Collection.Count();\r\n        for ( int i = 0; i \u003C count; i\u002B\u002B )\r\n        {\r\n            var item = Collection.ElementAt( i );\r\n            int index = num;\r\n            var itemLayout = Layout.Row();\r\n            itemLayout.Spacing = 4f;\r\n            // try to get object\r\n            if ( item.TryGetAsObject( out var obj ) )\r\n            {\r\n                var thing = new SFXRNoteSheet( obj );\r\n                itemLayout.Add( thing );\r\n            }\r\n            else\r\n            {\r\n                var thing = ControlWidget.Create( item );\r\n                thing.MinimumHeight = 100;\r\n                itemLayout.Add( thing );\r\n            }\r\n\r\n            var buttonLayout = Layout.Column();\r\n            if ( i \u003E 0 )\r\n            {\r\n                buttonLayout.Add( new IconButton( \u0022arrow_upward\u0022, delegate\r\n                {\r\n                    MoveUp( index );\r\n                } )\r\n                {\r\n                    Background = Color.Transparent,\r\n                    FixedWidth = ControlWidget.ControlRowHeight,\r\n                    FixedHeight = ControlWidget.ControlRowHeight,\r\n                    ToolTip = \u0022Move note up\u0022\r\n                } );\r\n            }\r\n            else\r\n            {\r\n                buttonLayout.AddSpacingCell( 25 );\r\n            }\r\n\r\n            buttonLayout.Add( new IconButton( \u0022delete\u0022, delegate\r\n            {\r\n                RemoveEntry( index );\r\n            } )\r\n            {\r\n                Background = Color.Red,\r\n                FixedWidth = ControlWidget.ControlRowHeight,\r\n                FixedHeight = ControlWidget.ControlRowHeight,\r\n                ToolTip = \u0022Delete note\u0022\r\n            } );\r\n\r\n            if ( i \u003C count - 1 )\r\n            {\r\n                buttonLayout.Add( new IconButton( \u0022arrow_downward\u0022, delegate\r\n                {\r\n                    MoveDown( index );\r\n                } )\r\n                {\r\n                    Background = Color.Transparent,\r\n                    FixedWidth = ControlWidget.ControlRowHeight,\r\n                    FixedHeight = ControlWidget.ControlRowHeight,\r\n                    ToolTip = \u0022Move note down\u0022\r\n                } );\r\n            }\r\n            else\r\n            {\r\n                buttonLayout.AddSpacingCell( 25 );\r\n            }\r\n\r\n            itemLayout.Add( buttonLayout );\r\n            layout.Add( itemLayout );\r\n            num\u002B\u002B;\r\n        }\r\n\r\n        MinimumHeight = 50 \u002B (num * 105);\r\n\r\n        Content.Add( layout );\r\n        Content.Margin = ((num \u003E 0) ? 3 : 0);\r\n    }\r\n\r\n    private void AddEntry()\r\n    {\r\n        Collection.Add( new SFXRSequencer.Note() );\r\n    }\r\n\r\n    private void RemoveEntry( int index )\r\n    {\r\n        Collection.RemoveAt( index );\r\n    }\r\n\r\n    private void MoveUp( int index )\r\n    {\r\n        // Move the index up in Sequencer.Notes list\r\n        if ( index \u003E 0 )\r\n        {\r\n            var note = Sequencer.Notes[index];\r\n            Sequencer.Notes.RemoveAt( index );\r\n            Sequencer.Notes.Insert( index - 1, note );\r\n        }\r\n\r\n        Rebuild();\r\n    }\r\n\r\n    private void MoveDown( int index )\r\n    {\r\n        // Move the index down in Sequencer.Notes list\r\n        if ( index \u003C Sequencer.Notes.Count - 1 )\r\n        {\r\n            var note = Sequencer.Notes[index];\r\n            Sequencer.Notes.RemoveAt( index );\r\n            Sequencer.Notes.Insert( index \u002B 1, note );\r\n        }\r\n\r\n        Rebuild();\r\n    }\r\n\r\n    protected override void OnPaint()\r\n    {\r\n\r\n    }\r\n\r\n    public void AddEffectDialog( Button source )\r\n    {\r\n        var s = new SFXREffectTypeSelector( this );\r\n        s.OnSelect \u002B= ( t ) =\u003E AddEffect( t );\r\n        s.OpenAt( source.ScreenRect.BottomLeft, animateOffset: new Vector2( 0, -4 ) );\r\n        s.FixedWidth = source.Width;\r\n    }\r\n\r\n    void AddEffect( TypeDescription type )\r\n    {\r\n        if ( !type.TargetType.IsAssignableTo( typeof( SFXREffect ) ) )\r\n        {\r\n            Log.Error( $\u0022Type {type.TargetType} is not assignable to {typeof( SFXREffect )}\u0022 );\r\n            return;\r\n        }\r\n\r\n        SFXREffect effect = type.Create\u003CSFXREffect\u003E();\r\n        Collection.Add( effect );\r\n\r\n        Log.Info( effect );\r\n    }\r\n\r\n\r\n}\r\n"},{"Ident":"carsonk.sfxr","Path":"Code/FX/Envelope.cs","FileName":"Envelope.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":55752,"IsPrivate":false,"Code":"using System;\r\nusing System.Collections.Generic;\r\nusing Sandbox;\r\n\r\nnamespace SFXR;\r\n\r\n[Title( \u0022ADSR Envelope\u0022 )]\r\n[Category( \u0022SFXR Effects\u0022 )]\r\n[Icon( \u0022mail_outline\u0022 )]\r\npublic class SFXREnvelope : SFXREffect\r\n{\r\n    /// \u003Csummary\u003E\r\n    /// Time the sound takes to reach its peak amplitude\r\n    /// (Default: 0)\r\n    /// \u003C/summary\u003E\r\n    [Property, Range( 0, 10 )]\r\n    public float Attack { get; set; } = 0;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// The time taken for the sound to fade to the sustain level\r\n    /// \u003C/summary\u003E\r\n    [Property, Range( 0, 10 )]\r\n    public float Decay { get; set; } = 0;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// The level maintained until release is triggered\r\n    /// (Default: 1)\r\n    /// \u003C/summary\u003E\r\n    [Property, Range( 0, 1 )]\r\n    public float Sustain { get; set; } = 1f;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// The time taken for the sound to fade to zero after the sustain\r\n    /// (Default: 0.3)\r\n    /// \u003C/summary\u003E\r\n    [Property, Range( 0, 10 )]\r\n    public float SustainTime { get; set; } = 0.3f;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// The time taken for the sound to fade to zero after the release\r\n    /// (Default: 0.4)\r\n    /// \u003C/summary\u003E\r\n    [Property, Range( 0, 10 )]\r\n    public float Release { get; set; } = 0.4f;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// Returns the amplitude of the envelope at a given time\r\n    /// \u003C/summary\u003E\r\n    /// \u003Cparam name=\u0022time\u0022\u003ETime in seconds\u003C/param\u003E\r\n    /// \u003Creturns\u003EAmplitude of the envelope at the given time\u003C/returns\u003E\r\n    public float GetAmplitude( float time )\r\n    {\r\n        return GetCurve().Evaluate( time / GetLength() );\r\n    }\r\n\r\n    public override short[] Apply( short[] samples, SFXRComponent sound )\r\n    {\r\n        // Calculate the envelope amplitude for each sample\r\n        for ( int i = 0; i \u003C samples.Length; i\u002B\u002B )\r\n        {\r\n            float t = i / (float)sound.SampleRate;\r\n            float amplitude = GetAmplitude( t );\r\n            samples[i] = (short)(samples[i] * amplitude);\r\n        }\r\n\r\n        return samples;\r\n    }\r\n\r\n    public float GetLength()\r\n    {\r\n        return Attack \u002B Decay \u002B SustainTime \u002B Release;\r\n    }\r\n\r\n    public Curve GetCurve()\r\n    {\r\n        Curve curve = new();\r\n\r\n        List\u003CVector2\u003E points = new();\r\n\r\n        // Add the attack curve\r\n        points.Add( new Vector2( 0, 0 ) );\r\n        points.Add( new Vector2( Attack, 1 ) );\r\n\r\n        // Add the decay curve\r\n        points.Add( new Vector2( Attack \u002B Decay, Sustain ) );\r\n\r\n        // Add the sustain curve\r\n        points.Add( new Vector2( Attack \u002B Decay \u002B SustainTime, Sustain ) );\r\n\r\n        // Add the release curve\r\n        points.Add( new Vector2( Attack \u002B Decay \u002B SustainTime \u002B Release, 0 ) );\r\n\r\n        // Normalize the curve to 0-1 in the x\r\n        for ( int i = 0; i \u003C points.Count; i\u002B\u002B )\r\n        {\r\n            points[i] = new Vector2( points[i].x / (Attack \u002B Decay \u002B SustainTime \u002B Release), points[i].y );\r\n        }\r\n\r\n        // Add the points to the curve\r\n        foreach ( var point in points )\r\n        {\r\n            curve.AddPoint( point.x, point.y );\r\n        }\r\n\r\n        return curve;\r\n    }\r\n}"},{"Ident":"carsonk.sfxr","Path":"Editor/SFXRComponentEditor.cs","FileName":"SFXRComponentEditor.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":55752,"IsPrivate":false,"Code":"using Editor;\r\nusing Sandbox;\r\nusing System.Linq;\r\n\r\nnamespace SFXR.Editor;\r\n\r\n//[CustomEditor( typeof( SFXRComponent ) )]\r\npublic class SFXRComponentEditor : ComponentEditorWidget\r\n{\r\n    //ParticleFloatControlWidget\r\n\r\n    public SFXRComponentEditor( SerializedObject obj ) : base( obj )\r\n    {\r\n\r\n        var defaultInspector = new PropertyControlSheet();\r\n        defaultInspector.AddObject( obj );\r\n\r\n        Layout = Layout.Column();\r\n        Layout.Add( defaultInspector );\r\n        Layout.AddSpacingCell( 5 );\r\n\r\n\r\n    }\r\n}"},{"Ident":"carsonk.sfxr","Path":"Code/SFXRSequencer.cs","FileName":"SFXRSequencer.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":55752,"IsPrivate":false,"Code":"using System.Collections.Generic;\r\nusing System.Linq;\r\nusing Sandbox;\r\n\r\nnamespace SFXR;\r\n\r\n[Title( \u0022SFXR Sequencer\u0022 )]\r\n[Category( \u0022SFXR\u0022 )]\r\n[Icon( \u0022view_comfy\u0022 )]\r\npublic class SFXRSequencer : Component\r\n{\r\n    [Property, Group( \u0022Settings\u0022 )]\r\n    public float BPM { get; set; } = 120;\r\n\r\n    [Property, Group( \u0022Settings\u0022 )]\r\n    public int BeatsPerBar { get; set; } = 4;\r\n\r\n    [Property, Group( \u0022Notes\u0022 )]\r\n    public List\u003CNote\u003E Notes { get; set; } = new();\r\n\r\n    [Property, Group( \u0022Controls\u0022 )]\r\n    public SFXRSequencerControls Controls { get; set; } = new();\r\n\r\n    public bool IsPlaying { get; private set; } = false;\r\n\r\n    public float CurrentTime { get; private set; } = 0f;\r\n\r\n    SFXRComponent Sfxr;\r\n    List\u003CNote\u003E NotesToPlay = new();\r\n    List\u003CNote\u003E NotesToStop = new();\r\n\r\n    protected override void OnDisabled()\r\n    {\r\n        Sfxr.TriggerReleaseAll();\r\n        StopSequence();\r\n    }\r\n\r\n    protected override void OnUpdate()\r\n    {\r\n        if ( !IsPlaying ) return;\r\n\r\n        Sfxr ??= GameObject.Components.Get\u003CSFXRComponent\u003E();\r\n\r\n        if ( Sfxr is null )\r\n        {\r\n            Log.Error( \u0022SFXRSequencer requires an SFXRComponent to be attached to the same GameObject\u0022 );\r\n            return;\r\n        }\r\n\r\n        CurrentTime \u002B= Time.Delta;\r\n\r\n        for ( int i = 0; i \u003C NotesToStop.Count; i\u002B\u002B )\r\n        {\r\n            var note = NotesToStop[i];\r\n            var time = BeatsToSeconds( note.Time \u002B note.Length );\r\n            if ( CurrentTime \u003E= time )\r\n            {\r\n                Sfxr.TriggerNoteRelease( note.Frequency );\r\n                NotesToStop.RemoveAt( i );\r\n                i--;\r\n            }\r\n        }\r\n\r\n        for ( int i = 0; i \u003C NotesToPlay.Count; i\u002B\u002B )\r\n        {\r\n            var note = NotesToPlay[i];\r\n            var time = BeatsToSeconds( note.Time );\r\n            if ( CurrentTime \u003E= time )\r\n            {\r\n                // Sfxr.Frequency.Start = note.Frequency;\r\n                // Sfxr.Length = BeatsToSeconds( note.Length );\r\n                // Sfxr.MasterVolume = note.Volume;\r\n                Sfxr.TriggerNotePress( note.Frequency, note.Volume );\r\n\r\n                NotesToStop.Add( note );\r\n                NotesToPlay.RemoveAt( i );\r\n                i--;\r\n            }\r\n        }\r\n\r\n        if ( NotesToPlay.Count == 0 \u0026\u0026 NotesToStop.Count == 0 )\r\n        {\r\n            IsPlaying = false;\r\n        }\r\n    }\r\n\r\n    public void PlaySequence()\r\n    {\r\n        if ( Sfxr is null )\r\n        {\r\n            Sfxr = GameObject.Components.Get\u003CSFXRComponent\u003E();\r\n        }\r\n        if ( !Sfxr.Enabled ) return;\r\n\r\n        IsPlaying = true;\r\n        CurrentTime = 0f;\r\n\r\n        NotesToPlay.Clear();\r\n        NotesToPlay.AddRange( Notes );\r\n    }\r\n\r\n    public void StopSequence()\r\n    {\r\n        IsPlaying = false;\r\n        CurrentTime = 0f;\r\n    }\r\n\r\n    public void PlayRange( float start, float end )\r\n    {\r\n        IsPlaying = true;\r\n        CurrentTime = BeatsToSeconds( start );\r\n\r\n        Sfxr.TriggerReleaseAll();\r\n        NotesToStop.Clear();\r\n\r\n        NotesToPlay.Clear();\r\n        NotesToPlay.AddRange( Notes.Where( x =\u003E x.Time \u003E= start \u0026\u0026 x.Time \u003C= end ) );\r\n    }\r\n\r\n    float BeatsToSeconds( float beats )\r\n    {\r\n        return beats * (60f / BPM / BeatsPerBar);\r\n    }\r\n\r\n    public class Note\r\n    {\r\n        [Property] public float Time { get; set; }\r\n        [Property] public float Frequency { get; set; }\r\n        [Property] public float Length { get; set; }\r\n        [Property] public float Volume { get; set; }\r\n\r\n        public Note()\r\n        {\r\n            Time = 0;\r\n            Frequency = 440;\r\n            Length = 1f;\r\n            Volume = 1f;\r\n        }\r\n    }\r\n\r\n}"},{"Ident":"carsonk.sfxr","Path":"Editor/SFXRFloatControlWidget.cs","FileName":"SFXRFloatControlWidget.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":55752,"IsPrivate":false,"Code":"using Sandbox;\r\nusing Editor;\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\n\r\nnamespace SFXR.Editor;\r\n\r\n//[CustomEditor( typeof( SFXRFloat ) )]\r\n// public class SFXRFloatControlWidget : ControlWidget\r\n// {\r\n\r\n//     SerializedObject Target;\r\n\r\n//     public SFXRFloatControlWidget( SerializedProperty property ) : base( property )\r\n//     {\r\n//         SetSizeMode( SizeMode.Ignore, SizeMode.Default );\r\n\r\n//         if ( !property.TryGetAsObject( out Target ) )\r\n//             return;\r\n\r\n//         Layout = Layout.Row();\r\n//         Layout.Spacing = 2;\r\n\r\n//         var value = Target.GetProperty( \u0022Value\u0022 );\r\n//         FloatControlWidget valueWidget = new FloatControlWidget( value );\r\n\r\n//         if ( property.TryGetAttribute\u003CRangeAttribute\u003E( out var attribute ) )\r\n//         {\r\n//             valueWidget.Range = new Vector2( attribute.Min, attribute.Max );\r\n//             valueWidget.RangeStep = attribute.Step;\r\n//             valueWidget.HasRange = attribute.Slider;\r\n//             // if ( attribute.Slider )\r\n//             // {\r\n//             //     sliderWidget = new FloatSlider( this );\r\n//             //     sliderWidget.HighlightColor = Theme.Grey;\r\n//             //     sliderWidget.Minimum = attribute.Min;\r\n//             //     sliderWidget.Maximum = attribute.Max;\r\n//             //     sliderWidget.Step = attribute.S;\r\n//             //     sliderWidget.OnValueEdited = delegate\r\n//             //     {\r\n//             //         base.SerializedProperty.As.Float = sliderWidget.Value;\r\n//             //     };\r\n//             // }\r\n//         }\r\n\r\n//         Layout.Add( valueWidget );\r\n\r\n//         var locked = Target.GetProperty( \u0022Locked\u0022 );\r\n//         IconButton lockedButton = new IconButton( \u0022lock_open\u0022 );\r\n//         lockedButton.OnClick = () =\u003E\r\n//         {\r\n//             if ( Target.Targets.First() is SFXRFloat sfxrFloat )\r\n//             {\r\n//                 sfxrFloat.Locked = !sfxrFloat.Locked;\r\n//                 Log.Info( sfxrFloat.Locked );\r\n//                 lockedButton.Icon = sfxrFloat.Locked ? \u0022lock\u0022 : \u0022lock_open\u0022;\r\n//                 lockedButton.Update();\r\n//             }\r\n//         };\r\n//         lockedButton.ToolTip = \u0022Lock/Unlock this value\u0022;\r\n//         Layout.Add( lockedButton );\r\n//     }\r\n\r\n//     protected override void OnPaint()\r\n//     {\r\n\r\n//     }\r\n\r\n// }\r\n\r\n// public class SFXRFloatControlWidget : FloatControlWidget\r\n// {\r\n\r\n//     SerializedObject Target;\r\n\r\n//     public SFXRFloatControlWidget( SerializedProperty property ) : base( property )\r\n//     {\r\n//         if ( !property.TryGetAsObject( out Target ) )\r\n//             return;\r\n\r\n//         var locked = Target.GetProperty( \u0022Locked\u0022 );\r\n//         IconButton lockedButton = new IconButton( \u0022lock_open\u0022 );\r\n//         lockedButton.OnClick = () =\u003E\r\n//         {\r\n//             // if ( Target.Targets.First() is SFXRFloat sfxrFloat )\r\n//             // {\r\n//             //     sfxrFloat.Locked = !sfxrFloat.Locked;\r\n//             //     Log.Info( sfxrFloat.Locked );\r\n//             //     lockedButton.Icon = sfxrFloat.Locked ? \u0022lock\u0022 : \u0022lock_open\u0022;\r\n//             //     lockedButton.Update();\r\n//             // }\r\n//         };\r\n//         lockedButton.ToolTip = \u0022Lock/Unlock this value\u0022;\r\n//         //Layout.Add( lockedButton );\r\n//     }\r\n\r\n//     protected override void PaintControl()\r\n//     {\r\n//         if ( Target is null ) return;\r\n\r\n//         base.PaintControl();\r\n//     }\r\n\r\n//     protected override void OnPaint()\r\n//     {\r\n//         if ( Target is null ) return;\r\n\r\n//         base.OnPaint();\r\n//     }\r\n// }"},{"Ident":"carsonk.sfxr","Path":"Editor/SFXRSoundControlWidget.cs","FileName":"SFXRSoundControlWidget.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":55752,"IsPrivate":false,"Code":"using Editor;\r\nusing Sandbox;\r\nusing System.Linq;\r\n\r\nnamespace SFXR.Editor;\r\n\r\n[CustomEditor( typeof( SFXRControls ) )]\r\npublic class SFXRSoundControlWidget : ControlWidget\r\n{\r\n\r\n    SerializedObject Target;\r\n\r\n    public SFXRSoundControlWidget( SerializedProperty property ) : base( property )\r\n    {\r\n\r\n        if ( !property.TryGetAsObject( out Target ) )\r\n            return;\r\n\r\n        var component = property.Parent.Targets.First() as SFXRComponent;\r\n\r\n        // Randomize Button\r\n        var btnRandomize = new Button( \u0022Randomize All\u0022, \u0022casino\u0022 );\r\n        btnRandomize.Clicked = () =\u003E\r\n        {\r\n            component.Randomize();\r\n            component.PlaySound();\r\n        };\r\n        btnRandomize.ToolTip = \u0022Randomize all sound properties\u0022;\r\n\r\n        // Play Sound Button\r\n        var btnPlaySound = new Button( \u0022Play Sound\u0022, \u0022play_arrow\u0022 );\r\n        btnPlaySound.Clicked = () =\u003E\r\n        {\r\n            component.PlaySound();\r\n        };\r\n        btnPlaySound.MinimumWidth = 200;\r\n        btnPlaySound.ToolTip = \u0022Play the current sound\u0022;\r\n\r\n        // Mutate Button\r\n        var btnMutate = new Button( \u0022Mutate\u0022, \u0022shuffle\u0022 );\r\n        btnMutate.Clicked = () =\u003E\r\n        {\r\n            component.Mutate();\r\n            component.PlaySound();\r\n        };\r\n        btnMutate.ToolTip = \u0022Mutate all sound properties\u0022;\r\n\r\n        // Randomize Pickup Button\r\n        var btnRandomizePickup = new Button( \u0022\u0022, \u0022monetization_on\u0022 );\r\n        btnRandomizePickup.Clicked = () =\u003E\r\n        {\r\n            component.RandomizePickup();\r\n            component.PlaySound();\r\n        };\r\n        btnRandomizePickup.ToolTip = \u0022Generate random pickup sound\u0022;\r\n\r\n        // Randomize Laser Button\r\n        var btnRandomizeLaser = new Button( \u0022\u0022, \u0022bolt\u0022 );\r\n        btnRandomizeLaser.Clicked = () =\u003E\r\n        {\r\n            component.RandomizeLaser();\r\n            component.PlaySound();\r\n        };\r\n        btnRandomizeLaser.ToolTip = \u0022Generate random laser sound\u0022;\r\n\r\n        // Randomize Explosion Button\r\n        var btnRandomizeExplosion = new Button( \u0022\u0022, \u0022flare\u0022 );\r\n        btnRandomizeExplosion.Clicked = () =\u003E\r\n        {\r\n            component.RandomizeExplosion();\r\n            component.PlaySound();\r\n        };\r\n        btnRandomizeExplosion.ToolTip = \u0022Generate random explosion sound\u0022;\r\n\r\n        // Randomize Powerup Button\r\n        var btnRandomizePowerup = new Button( \u0022\u0022, \u0022star\u0022 );\r\n        btnRandomizePowerup.Clicked = () =\u003E\r\n        {\r\n            component.RandomizePowerup();\r\n            component.PlaySound();\r\n        };\r\n        btnRandomizePowerup.ToolTip = \u0022Generate random powerup sound\u0022;\r\n\r\n        // Randomize Hit Hurt Button\r\n        var btnRandomizeHit = new Button( \u0022\u0022, \u0022sentiment_very_dissatisfied\u0022 );\r\n        btnRandomizeHit.Clicked = () =\u003E\r\n        {\r\n            component.RandomizeHit();\r\n            component.PlaySound();\r\n        };\r\n        btnRandomizeHit.ToolTip = \u0022Generate random hit/hurt sound\u0022;\r\n\r\n        // Randomize Jump Button\r\n        var btnRandomizeJump = new Button( \u0022\u0022, \u0022settings_accessibility\u0022 );\r\n        btnRandomizeJump.Clicked = () =\u003E\r\n        {\r\n            component.RandomizeJump();\r\n            component.PlaySound();\r\n        };\r\n        btnRandomizeJump.ToolTip = \u0022Generate random jump sound\u0022;\r\n\r\n        // Randomize Blip Select Button\r\n        var btnRandomizeBlipSelect = new Button( \u0022\u0022, \u0022menu\u0022 );\r\n        btnRandomizeBlipSelect.Clicked = () =\u003E\r\n        {\r\n            component.RandomizeBlip();\r\n            component.PlaySound();\r\n        };\r\n        btnRandomizeBlipSelect.ToolTip = \u0022Generate random blip/select sound\u0022;\r\n\r\n        Layout = Layout.Column();\r\n        Layout.Spacing = 2;\r\n        Layout.Margin = new Sandbox.UI.Margin( 0, 4 );\r\n        MinimumHeight = 90;\r\n\r\n        var grid = Layout.Grid();\r\n        grid.Spacing = 2;\r\n        grid.AddCell( 0, 0, btnRandomizePickup );\r\n        grid.AddCell( 1, 0, btnRandomizeLaser );\r\n        grid.AddCell( 2, 0, btnRandomizeExplosion );\r\n        grid.AddCell( 3, 0, btnRandomizePowerup );\r\n        grid.AddCell( 4, 0, btnRandomizeHit );\r\n        grid.AddCell( 5, 0, btnRandomizeJump );\r\n        grid.AddCell( 6, 0, btnRandomizeBlipSelect );\r\n\r\n        var randomRow = Layout.Row();\r\n        randomRow.Spacing = 2;\r\n        randomRow.Add( btnRandomize );\r\n        randomRow.Add( btnMutate );\r\n\r\n        Layout.Add( grid );\r\n        Layout.Add( randomRow );\r\n        Layout.Add( btnPlaySound );\r\n    }\r\n\r\n    protected override void OnPaint()\r\n    {\r\n    }\r\n\r\n}"},{"Ident":"carsonk.sfxr","Path":"Code/Values/SFXRFloat.cs","FileName":"SFXRFloat.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":55752,"IsPrivate":false,"Code":"using Sandbox;\r\nusing System;\r\nusing System.Text.Json.Serialization;\r\n\r\nnamespace SFXR;\r\n\r\npublic struct SFXRFloat\r\n{\r\n    [JsonInclude] public float Value { get; set; }\r\n    [JsonInclude] public bool Locked { get; set; }\r\n\r\n    public SFXRFloat( float value )\r\n    {\r\n        Value = value;\r\n        Locked = false;\r\n    }\r\n\r\n    public static implicit operator float( SFXRFloat value ) =\u003E value.Value;\r\n    public static implicit operator SFXRFloat( float value ) =\u003E new SFXRFloat( value );\r\n}"},{"Ident":"carsonk.sfxr","Path":"Editor/SFXRNoteWidget.cs","FileName":"SFXRNoteWidget.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":55752,"IsPrivate":false,"Code":"using Sandbox;\r\nusing Editor;\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing Sandbox.UI;\r\n\r\nnamespace SFXR.Editor;\r\n\r\npublic class SFXRNoteSheet : Widget\r\n{\r\n    public SFXRNoteSheet( SerializedObject obj ) : base( null )\r\n    {\r\n        var propertySheet = new PropertyControlSheet();\r\n        propertySheet.AddObject( obj );\r\n\r\n        Layout = Layout.Column();\r\n        Layout.Add( propertySheet );\r\n    }\r\n\r\n    protected override void OnPaint()\r\n    {\r\n        base.OnPaint();\r\n\r\n        Color color = Color.FromRgb( 0x111111 );\r\n        Paint.SetBrush( color );\r\n        Paint.SetPen( color );\r\n\r\n        Paint.DrawRect( new Rect( 0, 0, Width, Height ), 2 );\r\n    }\r\n\r\n}\r\n\r\n//[CustomEditor( typeof( SFXRFloat ) )]\r\n// public class SFXRFloatControlWidget : ControlWidget\r\n// {\r\n\r\n//     SerializedObject Target;\r\n\r\n//     public SFXRFloatControlWidget( SerializedProperty property ) : base( property )\r\n//     {\r\n//         SetSizeMode( SizeMode.Ignore, SizeMode.Default );\r\n\r\n//         if ( !property.TryGetAsObject( out Target ) )\r\n//             return;\r\n\r\n//         Layout = Layout.Row();\r\n//         Layout.Spacing = 2;\r\n\r\n//         var value = Target.GetProperty( \u0022Value\u0022 );\r\n//         FloatControlWidget valueWidget = new FloatControlWidget( value );\r\n\r\n//         if ( property.TryGetAttribute\u003CRangeAttribute\u003E( out var attribute ) )\r\n//         {\r\n//             valueWidget.Range = new Vector2( attribute.Min, attribute.Max );\r\n//             valueWidget.RangeStep = attribute.Step;\r\n//             valueWidget.HasRange = attribute.Slider;\r\n//             // if ( attribute.Slider )\r\n//             // {\r\n//             //     sliderWidget = new FloatSlider( this );\r\n//             //     sliderWidget.HighlightColor = Theme.Grey;\r\n//             //     sliderWidget.Minimum = attribute.Min;\r\n//             //     sliderWidget.Maximum = attribute.Max;\r\n//             //     sliderWidget.Step = attribute.S;\r\n//             //     sliderWidget.OnValueEdited = delegate\r\n//             //     {\r\n//             //         base.SerializedProperty.As.Float = sliderWidget.Value;\r\n//             //     };\r\n//             // }\r\n//         }\r\n\r\n//         Layout.Add( valueWidget );\r\n\r\n//         var locked = Target.GetProperty( \u0022Locked\u0022 );\r\n//         IconButton lockedButton = new IconButton( \u0022lock_open\u0022 );\r\n//         lockedButton.OnClick = () =\u003E\r\n//         {\r\n//             if ( Target.Targets.First() is SFXRFloat sfxrFloat )\r\n//             {\r\n//                 sfxrFloat.Locked = !sfxrFloat.Locked;\r\n//                 Log.Info( sfxrFloat.Locked );\r\n//                 lockedButton.Icon = sfxrFloat.Locked ? \u0022lock\u0022 : \u0022lock_open\u0022;\r\n//                 lockedButton.Update();\r\n//             }\r\n//         };\r\n//         lockedButton.ToolTip = \u0022Lock/Unlock this value\u0022;\r\n//         Layout.Add( lockedButton );\r\n//     }\r\n\r\n//     protected override void OnPaint()\r\n//     {\r\n\r\n//     }\r\n\r\n// }\r\n\r\n// public class SFXRFloatControlWidget : FloatControlWidget\r\n// {\r\n\r\n//     SerializedObject Target;\r\n\r\n//     public SFXRFloatControlWidget( SerializedProperty property ) : base( property )\r\n//     {\r\n//         if ( !property.TryGetAsObject( out Target ) )\r\n//             return;\r\n\r\n//         var locked = Target.GetProperty( \u0022Locked\u0022 );\r\n//         IconButton lockedButton = new IconButton( \u0022lock_open\u0022 );\r\n//         lockedButton.OnClick = () =\u003E\r\n//         {\r\n//             // if ( Target.Targets.First() is SFXRFloat sfxrFloat )\r\n//             // {\r\n//             //     sfxrFloat.Locked = !sfxrFloat.Locked;\r\n//             //     Log.Info( sfxrFloat.Locked );\r\n//             //     lockedButton.Icon = sfxrFloat.Locked ? \u0022lock\u0022 : \u0022lock_open\u0022;\r\n//             //     lockedButton.Update();\r\n//             // }\r\n//         };\r\n//         lockedButton.ToolTip = \u0022Lock/Unlock this value\u0022;\r\n//         //Layout.Add( lockedButton );\r\n//     }\r\n\r\n//     protected override void PaintControl()\r\n//     {\r\n//         if ( Target is null ) return;\r\n\r\n//         base.PaintControl();\r\n//     }\r\n\r\n//     protected override void OnPaint()\r\n//     {\r\n//         if ( Target is null ) return;\r\n\r\n//         base.OnPaint();\r\n//     }\r\n// }"},{"Ident":"carsonk.sfxr","Path":"Code/FX/HighPass.cs","FileName":"HighPass.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":55752,"IsPrivate":false,"Code":"\r\nusing System;\r\nusing Sandbox;\r\n\r\nnamespace SFXR;\r\n\r\n[Title( \u0022High Pass Filter\u0022 )]\r\n[Category( \u0022SFXR Effects\u0022 )]\r\n[Icon( \u0022align_horizontal_left\u0022 )]\r\npublic class SFXRHighPass : SFXREffect\r\n{\r\n    /// \u003Csummary\u003E\r\n    /// Cutoff value of the high-pass filter\r\n    /// (Default: 0, Range: 0 - 1)\r\n    /// \u003C/summary\u003E\r\n    [Property, Range( 0f, 12000f, 0.01f )]\r\n    public float Cutoff { get; set; } = 4000;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// Amount by which the high-pass cutoff frequency is increased or decreased over time\r\n    /// (Default: 0, Range: -1 - 1)\r\n    /// \u003C/summary\u003E\r\n    [Property, Range( -12000f, 12000f, 0.01f )]\r\n    public float Sweep { get; set; } = 0;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// Controls the high-pass filter\u0027s resonance (peak)\r\n    /// (Default: 0, Range: 0 - 1)\r\n    /// \u003C/summary\u003E\r\n    [Property, Range( 0f, 1f, 0.01f )]\r\n    public float Resonance { get; set; } = 0;\r\n\r\n    public override short[] Apply( short[] samples, SFXRComponent sound )\r\n    {\r\n        short[] outputSamples = new short[samples.Length];\r\n        double currentCutoff = Cutoff;\r\n        double previousInput = 0;\r\n        double previousOutput = 0;\r\n\r\n        for ( int i = 0; i \u003C samples.Length; i\u002B\u002B )\r\n        {\r\n            // Update cutoff frequency based on Sweep\r\n            currentCutoff \u002B= Sweep / (double)sound.SampleRate;\r\n\r\n            double RC = 1.0 / (2 * Math.PI * currentCutoff);\r\n            double dt = 1.0 / (double)sound.SampleRate;\r\n            double alpha = RC / (RC \u002B dt);\r\n\r\n            double inputSample = samples[i];\r\n            double outputSample = alpha * (previousOutput \u002B inputSample - previousInput);\r\n\r\n            // Apply resonance\r\n            if ( Resonance \u003E 0 )\r\n            {\r\n                double feedback = Resonance \u002B Resonance / (1 - currentCutoff);\r\n                outputSample = (1 - feedback) * outputSample \u002B feedback * previousOutput;\r\n            }\r\n\r\n            outputSamples[i] = (short)Math.Clamp( outputSample, short.MinValue, short.MaxValue );\r\n            previousInput = inputSample;\r\n            previousOutput = outputSample;\r\n        }\r\n\r\n        return outputSamples;\r\n    }\r\n}"},{"Ident":"carsonk.sfxr","Path":"Code/SFXREffect.cs","FileName":"SFXREffect.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":55752,"IsPrivate":false,"Code":"using System;\r\nusing Sandbox;\r\n\r\nnamespace SFXR;\r\n\r\npublic abstract class SFXREffect : Component\r\n{\r\n    /// \u003Csummary\u003E\r\n    /// Applies the effect to a sample\r\n    /// \u003C/summary\u003E\r\n    /// \u003Cparam name=\u0022samples\u0022\u003ESamples to apply the effect to\u003C/param\u003E\r\n    /// \u003Cparam name=\u0022sound\u0022\u003ESound applying the effect to\u003C/param\u003E\r\n    /// \u003Creturns\u003ESample with the effect applied\u003C/returns\u003E\r\n    public abstract short[] Apply( short[] samples, SFXRComponent sound );\r\n\r\n    /// \u003Csummary\u003E\r\n    /// Sanitizes the effect\u0027s parameters\r\n    /// \u003C/summary\u003E\r\n    public virtual void Sanitize()\r\n    {\r\n    }\r\n}"},{"Ident":"carsonk.sfxr","Path":"Editor/PropertyControlSheet.cs","FileName":"PropertyControlSheet.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":55752,"IsPrivate":false,"Code":"using Sandbox;\r\nusing Editor;\r\n\r\nnamespace SFXR.Editor;\r\n\r\npublic class PropertyControlSheet : GridLayout\r\n{\r\n\tpublic SerializedObject TargetObject { get; set; }\r\n\r\n\tint rows = 0;\r\n\r\n\tpublic PropertyControlSheet() : base()\r\n\t{\r\n\t\tMargin = new Sandbox.UI.Margin( 16, 8, 16, 8 );\r\n\t\tHorizontalSpacing = 10;\r\n\t\tVerticalSpacing = 2;\r\n\t\tSetColumnStretch( 1, 2 );\r\n\t\tSetMinimumColumnWidth( 0, 120 );\r\n\t}\r\n\r\n\tpublic void AddObject( SerializedObject obj )\r\n\t{\r\n\t\tforeach ( var entry in obj )\r\n\t\t{\r\n\t\t\tif ( !entry.HasAttribute\u003CPropertyAttribute\u003E() )\r\n\t\t\t{\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\t\t\tif ( entry.PropertyType.Name.StartsWith( \u0022Action\u0022 ) )\r\n\t\t\t{\r\n\t\t\t\tcontinue;\r\n\t\t\t}\r\n\r\n\t\t\tAddRow( entry );\r\n\t\t}\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Add a serialized property row. This will create an editor for the row and a label.\r\n\t/// \u003C/summary\u003E\r\n\tpublic void AddRow( SerializedProperty property, float labelIndent = 0.0f )\r\n\t{\r\n\t\tvar editor = ControlWidget.Create( property );\r\n\t\tif ( editor is null )\r\n\t\t\treturn;\r\n\r\n\t\tif ( editor.IsWideMode )\r\n\t\t{\r\n\t\t\tAddCell( 0, rows\u002B\u002B, new Label( property.DisplayName ) { MinimumHeight = Theme.RowHeight, Alignment = TextFlag.LeftCenter }, 2, 1, TextFlag.LeftTop );\r\n\t\t\tvar lo = AddCell( 0, rows, Layout.Column(), 2, 1, TextFlag.LeftTop );\r\n\r\n\t\t\tlo.Margin = new Sandbox.UI.Margin( 16, 0, 0, 0 );\r\n\t\t\tlo.Add( editor );\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tint cell = 0;\r\n\r\n\t\t\tvar label = AddCell( cell\u002B\u002B, rows, new Label( property.DisplayName ), 1, 1, TextFlag.LeftTop );\r\n\t\t\tlabel.MinimumHeight = Theme.RowHeight;\r\n\t\t\tlabel.Alignment = TextFlag.LeftCenter;\r\n\t\t\tlabel.SetStyles( \u0022color: #aaa;\u0022 );\r\n\r\n\t\t\tlabel.ToolTip = property.Description ?? property.DisplayName;\r\n\r\n\t\t\tif ( labelIndent \u003E 0 )\r\n\t\t\t{\r\n\t\t\t\tlabel.ContentMargins = new Sandbox.UI.Margin( labelIndent, 0, 0, 0 );\r\n\t\t\t}\r\n\r\n\t\t\tAddCell( cell\u002B\u002B, rows, editor, 1, 1, TextFlag.LeftTop );\r\n\t\t}\r\n\r\n\t\trows\u002B\u002B;\r\n\t}\r\n\r\n\t/// \u003Csummary\u003E\r\n\t/// Add a layout to a double wide cell\r\n\t/// \u003C/summary\u003E\r\n\tpublic void AddLayout( Layout layout )\r\n\t{\r\n\t\tAddCell( 0, rows\u002B\u002B, layout, 2, 1, TextFlag.LeftTop );\r\n\t}\r\n\r\n}"},{"Ident":"carsonk.sfxr","Path":"Code/SFXRWaveform.cs","FileName":"SFXRWaveform.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":55752,"IsPrivate":false,"Code":"using System;\r\nusing Sandbox;\r\nusing System.Text.Json.Serialization;\r\n\r\nnamespace SFXR;\r\n\r\npublic class SFXRWaveform\r\n{\r\n    public Curve Curve { get; set; }\r\n\r\n    public short Evaluate( float t )\r\n    {\r\n        return (short)(Curve.Evaluate( t ) * SFXR.MaxAmplitude);\r\n    }\r\n}"},{"Ident":"carsonk.sfxr","Path":"UnitTests/LibraryTest.cs","FileName":"LibraryTest.cs","PackageType":"library","CodeKind":"UnitTest","AssetVersionId":55752,"IsPrivate":false,"Code":"using Sandbox;\r\n\r\npublic partial class LibraryTests\r\n{\r\n\t[TestMethod]\r\n\tpublic void SceneTest()\r\n\t{\r\n\t\tvar scene = new Scene();\r\n\t\tusing ( scene.Push() )\r\n\t\t{\r\n\t\t\tvar go = new GameObject();\r\n\r\n\t\t\tAssert.AreEqual( 1, scene.Directory.GameObjectCount );\r\n\t\t}\r\n\t}\r\n\r\n}\r\n"},{"Ident":"carsonk.sfxr","Path":"Editor/Effects/SFXREnvelopeEditor.cs","FileName":"SFXREnvelopeEditor.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":55752,"IsPrivate":false,"Code":"using Editor;\r\nusing Sandbox;\r\nusing System.Linq;\r\n\r\nnamespace SFXR.Editor;\r\n\r\n[CustomEditor( typeof( SFXREnvelope ) )]\r\npublic class SFXREnvelopeEditor : ComponentEditorWidget\r\n{\r\n    SFXREnvelope Envelope;\r\n\r\n    public SFXREnvelopeEditor( SerializedObject obj ) : base( obj )\r\n    {\r\n\r\n        var defaultInspector = new PropertyControlSheet();\r\n        defaultInspector.AddObject( obj );\r\n\r\n        Envelope = obj.Targets.First() as SFXREnvelope;\r\n\r\n        Layout = Layout.Column();\r\n        Layout.Add( defaultInspector );\r\n        Layout.AddSpacingCell( 5 );\r\n\r\n        Layout.AddSpacingCell( 90 );\r\n    }\r\n\r\n    protected override void OnPaint()\r\n    {\r\n        base.OnPaint();\r\n\r\n        Rect adsrRect = new Rect( 12, 138, Width - 30, 80 );\r\n\r\n        Paint.SetBrush( Theme.ControlBackground );\r\n        Paint.SetPen( Theme.ControlBackground );\r\n        Paint.DrawRect( adsrRect, 2 );\r\n\r\n        Paint.SetPen( Theme.Green, 2 );\r\n\r\n        Envelope.GetCurve().DrawLine( adsrRect, 3, 0, 1 );\r\n\r\n    }\r\n}"},{"Ident":"carsonk.sfxr","Path":"Code/FX/Vibrato.cs","FileName":"Vibrato.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":55752,"IsPrivate":false,"Code":"using System;\r\nusing Sandbox;\r\n\r\nnamespace SFXR;\r\n\r\n[Title( \u0022Vibrato\u0022 )]\r\n[Category( \u0022SFXR Effects\u0022 )]\r\n[Icon( \u0022waves\u0022 )]\r\npublic class SFXRVibrato : SFXREffect\r\n{\r\n    /// \u003Csummary\u003E\r\n    /// Amount by which the frequency is changed\r\n    /// (Default: 0, Range: 0 - 1)\r\n    /// \u003C/summary\u003E\r\n    [Property, Range( 0f, 1f, 0.01f )] public float Depth { get; set; } = 0.3f;\r\n\r\n    /// \u003Csummary\u003E\r\n    /// Frequency of the vibrato in Hz\r\n    /// (Default: 0, Range: 0 - 100)\r\n    /// \u003C/summary\u003E\r\n    [Property, Range( 0f, 100f )]\r\n    public float Speed { get; set; } = 40;\r\n\r\n    public override short[] Apply( short[] samples, SFXRComponent sound )\r\n    {\r\n        if ( Depth == 0 || Speed == 0 )\r\n        {\r\n            return samples;\r\n        }\r\n\r\n        short[] outputSamples = new short[samples.Length];\r\n        double oscillatorPosition = 0;\r\n        double oscillatorIncrement = 2 * Math.PI * Speed / (double)sound.SampleRate;\r\n\r\n        for ( int i = 0; i \u003C samples.Length; i\u002B\u002B )\r\n        {\r\n\r\n            oscillatorPosition \u002B= oscillatorIncrement;\r\n            if ( oscillatorPosition \u003E 2 * Math.PI )\r\n            {\r\n                oscillatorPosition -= 2 * Math.PI;\r\n            }\r\n\r\n            double vibrato = Math.Sin( oscillatorPosition ) * Depth;\r\n\r\n            outputSamples[i] = (short)(samples[i] * (1 \u002B (float)vibrato));\r\n\r\n        }\r\n\r\n        return outputSamples;\r\n    }\r\n}"},{"Ident":"carsonk.sfxr","Path":"Editor/Effects/SFXREffectControlWidget.cs","FileName":"SFXREffectControlWidget.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":55752,"IsPrivate":false,"Code":"// using Editor;\r\n// using Sandbox;\r\n// using System.Linq;\r\n\r\n// namespace SFXR.Editor;\r\n\r\n// [CustomEditor( typeof( SFXREffect ) )]\r\n// public class SFXREffectControlWidget : ControlWidget\r\n// {\r\n\r\n//     public SFXREffectControlWidget( SerializedProperty property ) : base( property )\r\n//     {\r\n//         SetSizeMode( SizeMode.Ignore, SizeMode.Ignore );\r\n\r\n//         if ( !property.TryGetAsObject( out var target ) )\r\n//             return;\r\n\r\n//         // var component = property.Parent.Targets.First() as SFXRComponent;\r\n\r\n//         // Get the SFXRSound\r\n//         //var sound = property.Parent.Targets.First() as SFXRSound;\r\n\r\n//         Layout = Layout.Column();\r\n//         Layout.Spacing = 2;\r\n//         Layout.Margin = new Sandbox.UI.Margin( 0, 0 );\r\n\r\n//         SFXREffect effect = target.Targets.First() as SFXREffect;\r\n\r\n//         var properties = TypeLibrary.GetPropertyDescriptions( effect.GetType() );\r\n\r\n//         foreach ( var prop in properties )\r\n//         {\r\n//             Log.Info( prop );\r\n//         }\r\n//     }\r\n\r\n//     public void AddRow( SerializedProperty property, float labelIndent = 0.0f )\r\n//     {\r\n//         var editor = ControlWidget.Create( property );\r\n//         if ( editor is null )\r\n//             return;\r\n\r\n//         Layout.Add( editor );\r\n//     }\r\n\r\n\r\n\r\n// }\r\n"},{"Ident":"carsonk.sfxr","Path":"Code/SFXREnums.cs","FileName":"SFXREnums.cs","PackageType":"library","CodeKind":"Game","AssetVersionId":55752,"IsPrivate":false,"Code":"\r\nnamespace SFXR;\r\n\r\npublic enum Waveform\r\n{\r\n    Square,\r\n    Sawtooth,\r\n    Sine,\r\n    Noise\r\n}\r\n\r\npublic enum SampleRate\r\n{\r\n    Hz22050 = 22050,\r\n    Hz44100 = 44100,\r\n}\r\n\r\npublic enum BitDepth\r\n{\r\n    Bit0 = 0,\r\n    Bit8 = 8,\r\n    Bit16 = 16,\r\n}\r\n\r\npublic static partial class SFXR\r\n{\r\n    public static float GetMaxValue( this BitDepth depth )\r\n    {\r\n        switch ( depth )\r\n        {\r\n            case BitDepth.Bit0:\r\n                return 1;\r\n            case BitDepth.Bit8:\r\n                return 127;\r\n            case BitDepth.Bit16:\r\n                return 32767;\r\n            default:\r\n                throw new System.ArgumentException( \u0022Invalid bit depth\u0022 );\r\n        }\r\n    }\r\n}"},{"Ident":"carsonk.sfxr","Path":"Editor/SFXRSequencerControlWidget.cs","FileName":"SFXRSequencerControlWidget.cs","PackageType":"library","CodeKind":"Editor","AssetVersionId":55752,"IsPrivate":false,"Code":"using Editor;\r\nusing Sandbox;\r\nusing System.Linq;\r\n\r\nnamespace SFXR.Editor;\r\n\r\n[CustomEditor( typeof( SFXRSequencerControls ) )]\r\npublic class SFXRSequencerControlWidget : ControlWidget\r\n{\r\n\r\n    SerializedObject Target;\r\n\r\n    public SFXRSequencerControlWidget( SerializedProperty property ) : base( property )\r\n    {\r\n\r\n        if ( !property.TryGetAsObject( out Target ) )\r\n            return;\r\n\r\n        var component = property.Parent.Targets.First() as SFXRSequencer;\r\n\r\n        Layout = Layout.Column();\r\n        Layout.Spacing = 2;\r\n        Layout.Margin = new Sandbox.UI.Margin( 0, 4 );\r\n        MinimumHeight = 70;\r\n\r\n        Layout.Add( new Button( \u0022Play Sequence\u0022, \u0022play_arrow\u0022 )\r\n        {\r\n            Width = 200,\r\n            Clicked = () =\u003E\r\n            {\r\n                component.PlaySequence();\r\n            }\r\n        } );\r\n\r\n        Layout.Add( new Button( \u0022Stop Sequence\u0022, \u0022stop\u0022 )\r\n        {\r\n            Width = 200,\r\n            Clicked = () =\u003E\r\n            {\r\n                component.StopSequence();\r\n            }\r\n        } );\r\n    }\r\n\r\n    protected override void OnPaint()\r\n    {\r\n    }\r\n\r\n}"}]}