public void Read(string SampleName, string NoteSequence, string _volume) { float volume = 1f; if (_volume != null && _volume != String.Empty) { volume = Int32.Parse(_volume) / 100f; } this.notes = new List <acegiak_Note>(); foreach (string note in NoteSequence.Split(';')) { if (note != null && note.Length > 0) { string[] parts = note.Split(','); acegiak_Note noot = new acegiak_Note(SampleName, HzToMulti(ParseFloat(parts[0])), ParseFloat(parts[1]), ParseFloat(parts[2])); if (parts.Length > 3) { noot.volume = volume * ParseFloat(parts[3]); } else { noot.volume = volume; } this.notes.Add(noot); } } }
public void Update() { if (time != null && notes != null) { foreach (acegiak_Note note in notes) { if (note.begin > time && note.begin < time + Time.deltaTime) { //Debug.Log("start note"); note.Play(); } if (note.begin + note.length > time && note.begin + note.length < time + Time.deltaTime) { //Debug.Log("stop note"); note.Stop(); } } time += Time.deltaTime; } if (Rtime != null) { foreach (string i in keynotes.Keys.ToList()) { float rtime = Rtime ?? 0f; if (Input.GetKeyDown(i)) { if (notes.Count == 0) { Rtime = 0.01f; rtime = 0.01f; } acegiak_Note note = new acegiak_Note(recordVoice, HzToMulti((keynotes[i] * 2)), rtime, 0f); note.volume = recordVolume; note.Play(); notes.Add(note); //Debug.Log("START: "+i ); } if (Input.GetKeyUp(i)) { foreach (acegiak_Note note in notes) { if (note.pitch == HzToMulti((keynotes[i] * 2)) && note.length == 0) { note.length = rtime - note.begin; note.Stop(); //Debug.Log("END: "+i ); } } } } if (Input.GetKeyDown("return") || Input.GetKeyDown("escape")) { Rtime = null; } Rtime += Time.deltaTime; } }