private void EvaluateChord() { AudioManager.instance.PlayChord(chord.notes); AudioManager.instance.PlayNote(player); Note.Pitch p = player.pitch; if (player.accidental == Note.Accidental.Flat) { p = p - 1; } else if (player.accidental == Note.Accidental.Sharp) { p = p + 1; } if (p == chord.missingPitch) { popupTitle.text = "Correct!"; popupBody.text = "You win a point"; points++; scoreText.text = "score: " + points.ToString(); } else { popupTitle.text = "Incorrect!"; popupBody.text = "A" + (chord.root.IsAVowel() ? "n " : " ") + chord.ToString() + " chord contains a" + (player.IsAVowel() ? "n " : " ") + chord.missingPitchStr; } popup.SetActive(true); }
/// <summary> /// Retrieves the index, in the notes sound array, of the provided note /// </summary> /// <param name="pitch">the pitch of the note</param> /// <param name="octave">the ocatave of the note</param> /// <param name="accidental">the accidental of the note</param> /// <returns></returns> private int GetIndex(Note.Pitch pitch, int octave, Note.Accidental accidental) { int idx = (int)pitch; if (accidental == Note.Accidental.Flat) { idx--; } else if (accidental == Note.Accidental.Sharp) { idx++; } if (octave > 4 && pitch > Note.Pitch.B) { idx += (octave - 4) * 12; } else if (octave > 3 && pitch <= Note.Pitch.B) { idx += (octave - 3) * 12; } return(idx); }
public OffNote(Note.Pitch pitch) { this.NotePitch = pitch; }
/// <summary> /// Creates a chord using a string "root type" /// Examples: CMaj, DbMin7, FSus4 /// </summary> /// <param name="root">the root note of the chord</param> /// <param name="type">the type of chord</param> public void Initialize(string root, string type, LevelManager.Mode mode) { Clear(); rootStr = root; Debug.Log(root + type); // assign type to chord this.type = (Type)System.Enum.Parse(typeof(Type), type); for (int i = 0; i < 4; i++) { ledgerLines[i].SetActive(false); } // expand chord to get all notes List <string> expansion = new List <string>(); expansion.Add(root); switch (type) { case "Maj": expansion.Add(Note.GetInterval(root, 4)); expansion.Add(Note.GetInterval(root, 7)); break; case "Min": expansion.Add(Note.GetInterval(root, 3)); expansion.Add(Note.GetInterval(root, 7)); break; case "Dim": expansion.Add(Note.GetInterval(root, 3)); expansion.Add(Note.GetInterval(root, 6)); break; case "Aug": expansion.Add(Note.GetInterval(root, 4)); expansion.Add(Note.GetInterval(root, 8)); break; case "Sus2": expansion.Add(Note.GetInterval(root, 2)); expansion.Add(Note.GetInterval(root, 7)); break; case "Sus4": expansion.Add(Note.GetInterval(root, 5)); expansion.Add(Note.GetInterval(root, 7)); break; case "Maj7": expansion.Add(Note.GetInterval(root, 4)); expansion.Add(Note.GetInterval(root, 7)); expansion.Add(Note.GetInterval(root, 11)); break; case "Min7": expansion.Add(Note.GetInterval(root, 3)); expansion.Add(Note.GetInterval(root, 7)); expansion.Add(Note.GetInterval(root, 10)); break; case "Dim7": expansion.Add(Note.GetInterval(root, 3)); expansion.Add(Note.GetInterval(root, 6)); expansion.Add(Note.GetInterval(root, 9)); break; case "HDim7": expansion.Add(Note.GetInterval(root, 3)); expansion.Add(Note.GetInterval(root, 6)); expansion.Add(Note.GetInterval(root, 10)); break; } // decide which note will be dropped int missingNote = Random.Range(0, expansion.Count); int rootOctave = -1; for (int i = 0; i < expansion.Count; i++) { string s = expansion[i]; // decide octaves based on LevelManager's mode int noteOctave = GetOctave(s, root, rootOctave, this.type < Type.Maj7, mode); if (root.Equals(s)) { rootOctave = noteOctave; } if (i == missingNote) { missingPitchStr = s; if (s.Contains("#")) { s = Note.GetEnharmonic(s); } missingPitch = (Note.Pitch)System.Enum.Parse(typeof(Note.Pitch), s); } else { Note note = Instantiate(notePrefab, transform).GetComponent <Note>(); Debug.Log(s + " " + noteOctave); note.Initialize(s + noteOctave); float y = Note.NoteToY((Note.Pitch)System.Enum.Parse(typeof(Note.Pitch), s.ToCharArray()[0].ToString()), noteOctave); note.transform.localPosition = new Vector3(note.transform.localPosition.x, transform.position.y + y, note.transform.localPosition.z); notes.Add(note); // enable ledger lines if (y >= 4) { ledgerLines[0].SetActive(true); } if (y >= 3) { ledgerLines[1].SetActive(true); } if (y <= -3) { ledgerLines[2].SetActive(true); } if (y <= -4) { ledgerLines[3].SetActive(true); } } } this.root = notes[0]; }