void Update() { Assert.IsTrue(m_syncInfo.Count > 0); if (!m_bEnabled) { return; } if (m_playHead == 0.0) { m_nextSyncId = 0; Assert.IsTrue(m_syncInfo[m_nextSyncId].type == ELabel.Tempo); tempo = m_syncInfo[0].value; } else { int current_sync_id = 0; for (int i = 0; i < m_syncInfo.Count; ++i) { SSyncEntry se = m_syncInfo[i]; if (se.time > m_playHead) { m_nextSyncId = i; break; } else { current_sync_id = i; } } if (current_sync_id > m_currentSyncId) { // New sync occured //Debug.Log("Resync ID = " + current_sync_id); tempo = m_syncInfo[current_sync_id].value; if (tempo == 0) { OnPause(); } else { OnResync(); } } m_currentSyncId = current_sync_id; } m_playHead += Time.deltaTime; if (m_bTicking) { m_bpmTick -= Time.deltaTime; while (m_bpmTick <= 0.0) { m_bpmTick += m_bpmPeriod; Tick(m_tickType == 0); m_tickType = (m_tickType + 1) % 4; } } // Patternator UpdatePatternator(); }
void ParseLabelsInfo(TextAsset text_asset) { //StreamReader reader = new StreamReader("path"); //reader.ReadToEnd(); //reader.Close(); string text = text_asset.text; StringReader reader = new StringReader(text); string nextline = ""; while (nextline != null) { nextline = reader.ReadLine(); if (nextline != null && nextline.Length > 0) { // Format: double double string // both doubles are the same value (Audacity exported) // string formats: name, name=integer string[] elements = nextline.Split(new Char[] { ' ', '\t' }); //Debug.Log("How many elements = " + elements.Length.ToString()); Assert.IsTrue(elements.Length >= 3); if (elements.Length < 3) { continue; } double time = double.Parse(elements[0]); string[] tag = elements[2].Split('='); string tag0 = tag[0]; int value = 0; if (tag.Length > 1) { value = int.Parse(tag[1]); } ELabel type = ELabel.None; switch (tag0) { case "tempo": type = ELabel.Tempo; break; case "pause": type = ELabel.Pause; break; case "pattern": type = ELabel.Pattern; break; default: type = ELabel.None; break; } if (type == ELabel.Tempo || type == ELabel.Pause) { SSyncEntry se = new SSyncEntry(); se.type = type; se.time = time; se.tag = tag0; se.value = value; //Debug.Log("Parsed Entry @ " + se.time.ToString() + " seconds: " + se.tag + "(" + se.value + ")"); m_syncInfo.Add(se); } else { SPatternEntry pe = new SPatternEntry(); pe.time = time; pe.pattern = value; m_patternList.Add(pe); } } } //Debug.Log("DONE! number of entries = " + m_syncInfo.Count); }