public void PlayPattern(NotePattern pattern, float volume) { currentPattern = pattern; firstNoteTime = Time.time; currentNoteIdx = 0; curVolume = volume; }
public bool DoesPatternMatch(NotePattern pattern) { if (PatternListeningFor == null || pattern.Pattern.Count != PatternListeningFor.Pattern.Count) { return(false); } bool matches = true; for (int i = 0; i < PatternListeningFor.Pattern.Count; ++i) { // If the note doesn't match or the timing is wrong, reject match and break. if (pattern.Pattern[i].note != PatternListeningFor.Pattern[i].note || Mathf.Abs(pattern.Pattern[i].time - PatternListeningFor.Pattern[i].time) > NotePattern.halfNoteWindow) { matches = false; break; } } if (onMatchingNotes != null && matches) { onMatchingNotes.Invoke(pattern); } return(matches); }
public void Execute(NotePattern p) { Renderer rend = GetComponent <Renderer>(); rend.material.SetColor("_Color", Color.green); PlayPatternIdle idlePattern = GetComponent <PlayPatternIdle>(); idlePattern.enabled = false; playNotes.PlayPattern(p); }
public void NotifyListenersOfPattern(NotePattern pattern) { var allListeners = FindObjectsOfType(typeof(NoteListener)) as NoteListener[]; foreach (var listener in allListeners) { if (Vector3.Distance(listener.gameObject.transform.position, transform.position) <= listener.listenRadius) { listener.DoesPatternMatch(pattern); } } }
public void PlayBackLast() { if (lastRecorded == null) { Debug.Log("No last recorded file on record."); return; } string json = File.ReadAllText(dataPath + lastRecorded + ".json"); NotePattern nPattern = JsonUtility.FromJson <NotePattern>(json); PlayNotes playNotes = GetComponent <PlayNotes>(); playNotes.PlayPattern(nPattern); }
void Awake() { if (patternFile != null && patternFile != "") { try { string patternJson = File.ReadAllText(NotePattern.patternFilePath + patternFile + ".json"); PatternListeningFor = JsonUtility.FromJson <NotePattern>(patternJson); } catch (Exception e) { Debug.Log("Failed to open " + NotePattern.patternFilePath + patternFile + ".json" + ", error: " + e.Message); } } }
void Awake() { speakingNear = new List <PlayerNoteCreator>(); curState = IdlePatternState.PausedBetween; try { string json = File.ReadAllText(NotePattern.patternFilePath + patternFile + ".json"); pattern = JsonUtility.FromJson <NotePattern>(json); } catch (Exception e) { Debug.Log("Failed to open " + NotePattern.patternFilePath + patternFile + ".json" + ", error: " + e.Message); } }
void Update() { if (recording) { Note inputNote = Note.NONOTE; if (Input.GetButtonDown("NoteA")) { inputNote = Note.NoteA; playNotes.PlayPattern(NotePattern.soloA); } else if (Input.GetButtonDown("NoteB")) { inputNote = Note.NoteB; playNotes.PlayPattern(NotePattern.soloB); } else if (Input.GetButtonDown("NoteC")) { inputNote = Note.NoteC; playNotes.PlayPattern(NotePattern.soloC); } else if (Input.GetButtonDown("NoteD")) { inputNote = Note.NoteD; playNotes.PlayPattern(NotePattern.soloD); } if (inputNote != Note.NONOTE) { if (currentNotePattern == null) { currentNotePattern = new NotePattern(new List <NoteStamp> { new NoteStamp { note = inputNote, time = 0f } }); firstNoteTime = Time.time; } else { currentNotePattern.Pattern.Add(new NoteStamp { note = inputNote, time = Time.time - firstNoteTime }); } } else { if (currentNotePattern != null) { // Check if a second has passed since last note, stop recording if so. float deadTimePassed = Time.time - (firstNoteTime + currentNotePattern.Pattern[currentNotePattern.Pattern.Count - 1].time); Debug.Log(deadTimePassed); Debug.Log(currentNotePattern.Pattern.Count); if (currentNotePattern != null && deadTimePassed > NotePattern.patternEndWindow) { recording = false; recordButtonText.text = "Record"; firstNoteTime = -1f; string json = JsonUtility.ToJson(currentNotePattern); currentNotePattern = null; // Save currentNotePattern. if (fileName.text != null || fileName.text != "") { try { File.WriteAllText(dataPath + fileName.text + ".json", json); lastRecorded = fileName.text; lastRecordedTextDisplay.text = lastRecorded; } catch (Exception e) { Debug.Log("Failed to save pattern " + NotePattern.patternFilePath + fileName.text + ", error: " + e.Message); } } } } } } }
public void StopPlaying() { currentPattern = null; firstNoteTime = -1f; currentNoteIdx = -1; }
public void PlayPattern(NotePattern pattern) { PlayPattern(pattern, 1f); }
void Update() { Note inputNote = Note.NONOTE; if (Input.GetButtonDown("NoteA")) { inputNote = Note.NoteA; playNotes.PlayPattern(NotePattern.soloA); } else if (Input.GetButtonDown("NoteB")) { inputNote = Note.NoteB; playNotes.PlayPattern(NotePattern.soloB); } else if (Input.GetButtonDown("NoteC")) { inputNote = Note.NoteC; playNotes.PlayPattern(NotePattern.soloC); } else if (Input.GetButtonDown("NoteD")) { inputNote = Note.NoteD; playNotes.PlayPattern(NotePattern.soloD); } if (inputNote != Note.NONOTE) { if (currentNotePattern == null) { currentNotePattern = new NotePattern(new List <NoteStamp> { new NoteStamp { note = inputNote, time = 0f } }); firstNoteTime = Time.time; } else { currentNotePattern.Pattern.Add(new NoteStamp { note = inputNote, time = Time.time - firstNoteTime }); } } else { if (currentNotePattern != null) { // Check if a second has passed since last note, stop recording if so. float deadTimePassed = Time.time - (firstNoteTime + currentNotePattern.Pattern[currentNotePattern.Pattern.Count - 1].time); if (currentNotePattern != null && deadTimePassed > NotePattern.patternEndWindow) { NotifyListenersOfPattern(currentNotePattern); firstNoteTime = -1f; currentNotePattern = null; } } } }