heavy icon indicating copy to clipboard operation
heavy copied to clipboard

Mapping UI Slide to Hv AudioLib parameters

Open fr4nky8oy opened this issue 7 years ago • 6 comments

Hi Joe, i am making a UI for the FM PD patch in Unity I am having some problems understanding why i dont see the Hv AudioLib UI parameters from the UI Slide event Horizontal and Vertical. (please see pics)

do i need to create another script to access the Hv AudioLib UI parameters from the slider event? Thanks Joe,

capture2

capture1

fr4nky8oy avatar Jun 13 '17 10:06 fr4nky8oy

Yeah, I didn't think about this, so I might need to revisit the AudioLib interface add some point to enable this kind of support.

But you're right, you can write a wrapper script to forward your event updates to the AudioLib script.

Say you have a public float parameter

public class MyForwarder : MonoBehavior {
 private Hv_example_AudioLib script;
 public static float myParam 
 {
     get{return script.GetFloatParameter(Hv_example_AudioLib.Parameter.myParam); }
     set
     {   
          script.SetFloatParameter(Hv_example_AudioLib.Parameter.myParam, value);
     }
 }
 public Awake() {
    script = GetComponent<Hv_example_AudioLib>();
 } 
}

And attach this script at the same level as the AudioLib component on your gameobject.

Note: this is untested code but this is how I would probably attempt it!

diplojocus avatar Jun 13 '17 10:06 diplojocus

Amazing, thanks Joe will try this.

fr4nky8oy avatar Jun 13 '17 10:06 fr4nky8oy

Hi Joe, I have tried your code, it works! i can see the parameters now. the only thing i had to add to the script was static to private Hv_FM_test_AudioLib script; I am going to map away now .. and report back.thanks alot

    public class WrapperTest : MonoBehaviour {
private static Hv_FM_test_AudioLib script;
public static float Amp
{
	get{return script.GetFloatParameter(Hv_FM_test_AudioLib.Parameter.Amp); }
	set
	{   
		script.SetFloatParameter(Hv_FM_test_AudioLib.Parameter.Amp, value);
	}
}
public void Awake() {
	script = GetComponent<Hv_FM_test_AudioLib>();
}

public static float Carrier
{
	get{return script.GetFloatParameter(Hv_FM_test_AudioLib.Parameter.Amp); }
	set
	{   
		script.SetFloatParameter(Hv_FM_test_AudioLib.Parameter.Carrier, value);
	}
}

}

fr4nky8oy avatar Jun 14 '17 16:06 fr4nky8oy

Cool! Ahh yeah that makes sense, you probably don't want it static, if you remove the static keyword from the public static float Amp declaration then you should be able to avoid setting the AudioLib to static.

diplojocus avatar Jun 14 '17 16:06 diplojocus

coolio, I have changed it, no errors, happy times, thanks Joe

fr4nky8oy avatar Jun 14 '17 16:06 fr4nky8oy

Was unable to get this working. This was sending this error to the log.

Assets/Plugins/MacOSX/PortForward.cs(17,12): error CS1520: Class, struct, or interface method must have a return type

I ended up solving this issue with this. I am able to access the value and edit it in a UI Slider OnValueChanged as a Dynamic Float.

public class FloatForward : MonoBehaviour {

    public void TestValue(float value)
    {
        Hv_helloWorld_AudioLib script = GetComponent<Hv_helloWorld_AudioLib>();
        script.SetFloatParameter(Hv_helloWorld_AudioLib.Parameter.Freq, value);
    }

 }

Just a warning, but for some reason changing the slider value in the editor will just throw up warnings and not work. Seems like a long standing issue with Unity.

SendMessage cannot be called during Awake, CheckConsistency, or OnValidate UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

KyleWerle avatar Jul 15 '18 04:07 KyleWerle