heavy icon indicating copy to clipboard operation
heavy copied to clipboard

Controlling a heavy script in Unity

Open fr4nky8oy opened this issue 7 years ago • 17 comments

Hi guys, could you please help me with this test patch.

I have made a Controller Script in Unity to modify Frequency(FQ) and Wavetoogle(WT) on the PD/Heavy patch. The general Audio is fine, the heavy patch works great in play mode.

I think the Controller Script is wrong. In play mode the keys A and S do change the FQ and WT on the patch(on game object), but the sound does not change. Not sure why.

I am also getting some errors in the console (SendBangToReceiver..) but I have difficulties to identify the correct parameter in the Heavy/Patch script (not sure if parameter is the right word), so i can replace the SendBangToReceive.

I have attached the unity project below. please let me know if you could help to work it out. thank you.

https://www.dropbox.com/s/sifbkqa6iidu6zz/Procedural%20Audio.zip?dl=0

fr4nky8oy avatar May 31 '17 17:05 fr4nky8oy

Can you paste your controller script code here?

Are you using @hv_event for bangs into the patch?

diplojocus avatar May 31 '17 17:05 diplojocus

using UnityEngine; using System.Collections;

public class ControlScript : MonoBehaviour {

public Hv_OSC_Unity_AudioLib HeavyScript; 

// Use this for initialization
void Start () {


}

// Update is called once per frame
void Update () {

	if (Input.GetKeyDown ("space"))
		
	{
		HeavyScript.SendBangToReceiver ("onOff");
		//print ("space pressed");
	}
	
	else if (Input.GetKeyDown ("q"))

	{
		HeavyScript.SendBangToReceiver ("waveToggle");
		//print ("space pressed");

	}

	else if (Input.GetKey ("a"))
		
	{
		HeavyScript.freq -= 2;
		//print ("space pressed");
	}

	else if (Input.GetKey ("s"))
		
	{
		HeavyScript.freq += 2;
		//print ("space pressed");
	}



	else
		{
		return;
		}
	}

}

fr4nky8oy avatar May 31 '17 17:05 fr4nky8oy

I’m pretty sure you can’t send remote messages like this from Unity?

Also when addressing a remote parameter in Hv you need to use the following syntax :

for bangs

pd.SendEvent(Hv_script_AudioLib.Event.BangLabel);

for floats

pd.SetFloatParameter(Hv_script_AudioLib.Parameter.ParamLabel, var);

On 31 May 2017, at 18:03, fr4nky8oy [email protected] wrote:

Hi guys, could you please help me with this test patch.

I have made a Controller Script in Unity to modify Frequency(FQ) and Wavetoogle(WT) on the PD/Heavy patch. The general Audio is fine, the heavy patch works great in play mode.

I think the Controller Script that is wrong, for example in play mode the letter A and S change the FQ and WT on the patch(on game object) but the sound does not change. Not sure why.

I am also getting some errors in the console (SendBangToReceiver..) but I have difficulties to identify the correct parameter in the Heavy/Patch script (not sure if parameter is the right word), so i can replace the SendBangToReceive. I have attached the unity project below. please let me know if you could help to work it out. thank you.

https://www.dropbox.com/s/sifbkqa6iidu6zz/Procedural%20Audio.zip?dl=0 https://www.dropbox.com/s/sifbkqa6iidu6zz/Procedural%20Audio.zip?dl=0 — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/enzienaudio/heavy/issues/210, or mute the thread https://github.com/notifications/unsubscribe-auth/AT-_1ZdaY9KroZgLtocO8SQ1zdbiGm9Dks5r_Z1XgaJpZM4Nr67T.

dbaxaudio avatar May 31 '17 17:05 dbaxaudio

@dbaxaudio i followed this https://www.youtube.com/watch?v=NvoPwlZt8_A&t=77s

fr4nky8oy avatar May 31 '17 17:05 fr4nky8oy

@dbaxaudio 's example is correct, @fr4nky8oy that video you linked is quite old now.

Check the documentation https://enzienaudio.com/docs/index.html#06.unity#exposing-and-sending-events

Also there's example code in the AudioLib.cs script itself if you have a peek in there.

diplojocus avatar May 31 '17 17:05 diplojocus

Also don't use the public float values to update the patch (I need to remove those!).

You should use SetFloatParameter instead, see here: https://enzienaudio.com/docs/index.html#06.unity#exposing-and-setting-parameters

diplojocus avatar May 31 '17 17:05 diplojocus

thanks Joe, I checked all examples already, but i dont understand how to implement them in my code controller code :( , do you think you could copy/paste an example here pls?

fr4nky8oy avatar May 31 '17 17:05 fr4nky8oy

This works. Be sure to use a capital on any parameter names you have chosen

else if (Input.GetKey ("a"))

    {
        

        HeavyScript.SetFloatParameter(Hv_OSC_Unity_AudioLib.Parameter.Freq, 320.0f);
        //print ("space pressed");
    }

    else if (Input.GetKey ("s"))
        
    {
        HeavyScript.SetFloatParameter(Hv_OSC_Unity_AudioLib.Parameter.Freq, 340.0f);
        //print ("space pressed");
    } 

On 31 May 2017, at 18:26, fr4nky8oy [email protected] wrote:

thanks Joe, I checked all examples already, but i dont understand how to implement them in my code controller code :( , do you think you could copy/paste an example here pls?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/enzienaudio/heavy/issues/210#issuecomment-305258592, or mute the thread https://github.com/notifications/unsubscribe-auth/AT-_1dgRVaFh_lXslHOxI2uMOolL321Oks5r_aLhgaJpZM4Nr67T.

dbaxaudio avatar May 31 '17 17:05 dbaxaudio

amazing thanks, will try it now

fr4nky8oy avatar May 31 '17 17:05 fr4nky8oy

works great thanks guys, could you pls explain i could implement the -=2 and +=3 Fq changes, instead of setting a fixed float like 320.0f and 340.0f . do i need to make a public operation and then replace the float ?

thanks

fr4nky8oy avatar May 31 '17 18:05 fr4nky8oy

I think your best manipulating a variable inside a function, and then assigning the variable in the SetFloat

Or you could do the operations in PD and use a bang event to trigger them

On 31 May 2017, at 19:02, fr4nky8oy [email protected] wrote:

work great thanks guys, could you pls explain i could implement the -=2 and +=3 Fq changes, instead of setting a fixed float like 320.0f and 340.0f . do i need to make a public operation and then replace the float ?

thanks

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/enzienaudio/heavy/issues/210#issuecomment-305268883, or mute the thread https://github.com/notifications/unsubscribe-auth/AT-_1Z-Zt1cFRl36fe1gKK_rEbOqLNy8ks5r_atPgaJpZM4Nr67T.

dbaxaudio avatar May 31 '17 18:05 dbaxaudio

i like the first option, i need to research how to implement that thanks!

fr4nky8oy avatar May 31 '17 18:05 fr4nky8oy

Hey @fr4nky8oy the docs explain how to do this https://enzienaudio.com/docs/index.html#06.unity#exposing-and-setting-parameters

// increment parameter 'freq' by 1
float freq = script.GetFloatParameter(Hv_example_AudioLib.Parameter.Freq);
script.SetFloatParameter(Hv_example_AudioLib.Parameter.Freq, freq + 0.1f);

diplojocus avatar May 31 '17 20:05 diplojocus

thanks Joe!!

fr4nky8oy avatar Jun 01 '17 15:06 fr4nky8oy

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 12 '17 20:06 fr4nky8oy

Hey @fr4nky8oy can you make a separate issue for this and I'll reply in there. Thanks!

diplojocus avatar Jun 13 '17 10:06 diplojocus

great thanks Joe

fr4nky8oy avatar Jun 13 '17 10:06 fr4nky8oy