Skip to content

Commit

Permalink
fix: quantification (rapport au tempo)
Browse files Browse the repository at this point in the history
  • Loading branch information
Napolitain committed Jan 9, 2022
1 parent c6730f4 commit 89a7a7f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
14 changes: 11 additions & 3 deletions Assets/Scripts/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Game : MonoBehaviour
{
// audio
public static float QUANTIZATION = Quantization.NONE;
public static int TEMPO = 76;
public static float TEMPO = 76.0f;
public static float currentTime = 0f; // temps absolu (tempo = 60)
public static float CurrentTime { get => currentTime / (TEMPO / 60.0f); } // temps relatif (tempo pris en compte)
public static float DeltaTime { get => Time.deltaTime / (TEMPO / 60.0f); } // delta time relatif au tempo
Expand Down Expand Up @@ -71,8 +71,16 @@ public static float CurrentTimeQuantized
}
else
{
return (Mathf.Round(currentTime / QUANTIZATION) * QUANTIZATION + QUANTIZATION / 2) / (TEMPO / 60.0f);
return (Mathf.Round(currentTime / NormalizedQuantization) * NormalizedQuantization + NormalizedQuantization / 2);
}
}
}
}

/// <summary>
/// Normalise la quantification au tempo.
/// </summary>
public static float NormalizedQuantization
{
get => QUANTIZATION / TEMPO * 60.0f;
}
}
2 changes: 1 addition & 1 deletion Assets/Scripts/Model/Chords.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static Chords Recognize(List<Note> notes, bool sorted = false)
for (int i = 0; i < notes.Count; i++)
{
t[(int)transposed[i].name] = true;
UnityEngine.Debug.Log(transposed[i].ToString() + " " + t[(int)transposed[i].name]);
//UnityEngine.Debug.Log(transposed[i].ToString() + " " + t[(int)transposed[i].name]);
}
// comparer
for (int i = 0; i < TYPES_NUMBER; i++) // iterer la liste des accords
Expand Down
8 changes: 4 additions & 4 deletions Assets/Scripts/Model/Note.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ public Note Transpose(int semitones)
{
st = (int)(12 - (st - name));
o++;
UnityEngine.Debug.Log(this.ToString() + " " + new Note((NoteName)st, tone - o).ToString() + " " + semitones + " " + st + " " + o);
//UnityEngine.Debug.Log(this.ToString() + " " + new Note((NoteName)st, tone - o).ToString() + " " + semitones + " " + st + " " + o);
return new Note((NoteName)st, tone - o);
}
UnityEngine.Debug.Log(this.ToString() + " " + new Note(name - st, tone - o).ToString() + " " + semitones + " " + st + " " + o);
//UnityEngine.Debug.Log(this.ToString() + " " + new Note(name - st, tone - o).ToString() + " " + semitones + " " + st + " " + o);
return new Note(name - st, tone - o);
}
else
Expand All @@ -141,10 +141,10 @@ public Note Transpose(int semitones)
{
st = (int)(name + st) % 12;
o++;
UnityEngine.Debug.Log(this.ToString() + " " + new Note(name + st, tone + o).ToString() + " " + semitones + " " + st + " " + o);
//UnityEngine.Debug.Log(this.ToString() + " " + new Note(name + st, tone + o).ToString() + " " + semitones + " " + st + " " + o);
return new Note(name + st, tone + o);
}
UnityEngine.Debug.Log(this.ToString() + " " + new Note(name + st, tone + o).ToString() + " " + semitones + " " + st + " " + o);
//UnityEngine.Debug.Log(this.ToString() + " " + new Note(name + st, tone + o).ToString() + " " + semitones + " " + st + " " + o);
return new Note(name + st, tone + o);
}
}
Expand Down
10 changes: 5 additions & 5 deletions Assets/Scripts/PianoToucheScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ void Start()
void Update()
{
// quantification de notes
if (Game.CurrentTime >= playNote)
if (playNote != -1f && Game.currentTime >= playNote)
{
//Debug.Log(playNote + " " + Game.currentTime);
Debug.Log(playNote + " " + Game.currentTime);
PlayNote();
}
// release de la touche jusqu'a fin de note (release_time)
if (Game.CurrentTime >= release)
if (release != Mathf.Infinity && Game.currentTime >= release)
{
release_tmp += Time.deltaTime;
audioSource.volume -= Time.deltaTime / RELEASE_TIME;
Expand All @@ -102,7 +102,7 @@ void Update()
if (Game.song.currentEvents[i].notes.Contains(note))
{
//Debug.Log("Play: " + note.ToString());
playNote = Game.song.currentEvents[i].attack;
//playNote = Game.song.currentEvents[i].attack;
}
}
}
Expand Down Expand Up @@ -130,7 +130,7 @@ void OnTriggerEnter(Collider collider)
//if (Game.frame.Hands[a / 5].Fingers[a % 5].IsExtended) // joue le son
//{
//Debug.Log("Note " + note.ToString() + " détectée: " + Game.CurrentTime);
Debug.Log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>");
//Debug.Log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>");
audioSource.volume = Mathf.Max(VOLUME_MIN, VOLUME_MAX * Mathf.Min(VELOCITY_MAX, collider.GetComponent<VelocityFinger>().velocity) / VELOCITY_MAX);
playNote = Game.CurrentTimeQuantized;
Chords.currentChords.Add(note);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/UI/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private void ValueChangeCheck()
{
if (settingsTempo.text.Length != 0)
{
Game.TEMPO = int.Parse(settingsTempo.text);
Game.TEMPO = float.Parse(settingsTempo.text);
settingsTempo.placeholder.GetComponent<Text>().text = "Tempo: " + settingsTempo.text;
settingsTempo.text = "";
Debug.Log(Game.TEMPO);
Expand Down

0 comments on commit 89a7a7f

Please sign in to comment.