Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set audio plugin's parameter when a key is pressed #48

Open
JimPapanick opened this issue Sep 24, 2024 · 4 comments
Open

Set audio plugin's parameter when a key is pressed #48

JimPapanick opened this issue Sep 24, 2024 · 4 comments
Assignees

Comments

@JimPapanick
Copy link

JimPapanick commented Sep 24, 2024

Hey guys I need to set a parameter from an audio plugin set to 1 from 0 so that it sends a bang and sets some values depending on another objects current value. Here's the screenshot. The desired parameters are on the top right
image
This is the script that controlls the Lowest and Highest parameters that when set to 1 will store the lowest fzero value when u sing a low note and hit L and when you press H it will store another fzero value. But I don't see it logging that it is setting anything. What is going wrong?

`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class KeyParameterPress : MonoBehaviour
{
// Helper and plugin handle for Fzero1234New plugin
Fzero1234NewHelper fzeroHelper;
Fzero1234NewHandle fzeroPlugin;

// Constant representing the instance index of the plugin
const int instanceIndex = 1;

// Parameter indices for Lowest and Highest
readonly System.Int32 lowestParamIndex = (int)Fzero1234NewHandle.GetParamIndexById("Lowest");
readonly System.Int32 highestParamIndex = (int)Fzero1234NewHandle.GetParamIndexById("Highest");

void Start()
{
	// Find the plugin instance using the helper
	fzeroHelper = Fzero1234NewHelper.FindById(instanceIndex);
	fzeroPlugin = fzeroHelper.Plugin;

	if (fzeroPlugin == null)
	{
		Debug.LogError("Failed to retrieve plugin handle.");
	}
	else
	{
		Debug.Log("Successfully retrieved plugin handle.");
	}
}

void Update()
{
	if (fzeroPlugin == null) return; // Ensure the plugin is available

	// Check if "L" key is pressed
	if (Input.GetKeyDown(KeyCode.L))
	{
		// Set the "Lowest" parameter to 1
		fzeroPlugin.SetParamValue(lowestParamIndex, 1f);
		Debug.Log("Attempted to set 'Lowest' parameter to 1.");

		// Check if the parameter was actually set
		double lowestValue;
		fzeroPlugin.GetParamValue(lowestParamIndex, out lowestValue);
		Debug.Log("Current 'Lowest' parameter value: " + lowestValue);
	}

	// Check if "H" key is pressed
	if (Input.GetKeyDown(KeyCode.H))
	{
		// Set the "Highest" parameter to 1
		fzeroPlugin.SetParamValue(highestParamIndex, 1f);
		Debug.Log("Attempted to set 'Highest' parameter to 1.");

		// Check if the parameter was actually set
		double highestValue;
		fzeroPlugin.GetParamValue(highestParamIndex, out highestValue);
		Debug.Log("Current 'Highest' parameter value: " + highestValue);
	}

	// Optional: Reset parameters when keys are released
	if (Input.GetKeyUp(KeyCode.L))
	{
		fzeroPlugin.SetParamValue(lowestParamIndex, 0f);
		Debug.Log("Reset 'Lowest' parameter to 0.");
	}

	if (Input.GetKeyUp(KeyCode.H))
	{
		fzeroPlugin.SetParamValue(highestParamIndex, 0f);
		Debug.Log("Reset 'Highest' parameter to 0.");
	}
}

}
`

@jinpavg
Copy link
Contributor

jinpavg commented Sep 25, 2024

Hi @JimPapanick -- yes, I'm curious if sending a message into your RNBO device might work better for you here: https://github.com/Cycling74/rnbo.unity.audioplugin/blob/main/docs/MESSAGES.md

@jinpavg jinpavg self-assigned this Sep 25, 2024
@JimPapanick
Copy link
Author

Do I need to change my plugin whatsoever for this to work? Or just the script will do?

@jinpavg
Copy link
Contributor

jinpavg commented Sep 27, 2024

Hi Jim -- yes... you'd need to have a message inport that leads to your button in order to address that message inport from your script. So for example, instead of param Lowest @min 0 @max 1, you'd have something like an inport lowestTrigger in your patch, which you could connect up in C# like:

readonly System.UInt32 lowestInport = YourDeviceHandle.Tag("lowestTrigger");

and then later send a message to:

yourDeviceHandlePlugin.SendMessage(lowestInport , 1);

according to the document above.

Does this make sense?

@JimPapanick
Copy link
Author

JimPapanick commented Sep 27, 2024

why is this approach better than SetParamValue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants