Skip to content

Instantly share code, notes, and snippets.

@fengye
Last active January 21, 2017 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fengye/0502b863292c66520e4fd0830495a5d7 to your computer and use it in GitHub Desktop.
Save fengye/0502b863292c66520e4fd0830495a5d7 to your computer and use it in GitHub Desktop.
if (midiNote > 0)
{
int octave = midiNote / 12;
int noteNum = midiNote % 12;
int normalizedNote;
if (octave % 2 == 0)
{
normalizedNote = noteNum;
}
else
{
normalizedNote = (12 - 1) - noteNum;
}
// normalizedNote range == [0, 11]
// int normalizedNote = midiNote - 50;
// normalizedNote = (int)Mathf.Clamp(normalizedNote, -4, 4);
normalizedNote -= 6;
// normalizedNote range == [-6, 5]
if (turningPolicy == TurningPolicy.DIRECT ||
turningPolicy == TurningPolicy.DIRECT_SILENCE_TO_NEUTRAL)
{
cachedTargetRotation.eulerAngles = new Vector3(0, 0, -normalizedNote * 15.0f);
}
lastNormalizedNote = normalizedNote;
// transform.rotation = rot;
// Debug.Log("Detected note: " + midiNote);
Debug.Log("Detected freq: " + freq + " - Note: " + midiNote);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment