//this is where the magic happens private void OnOnset(OnsetType type, Onset onset) { if (type == OnsetType.All) { BeatPattern pattern = SelectPattern(Random.Range(0, patterns.Count)); //randomly select a supplied pattern object List <int> beatList = pattern.pattern; //copy the beat data from the pattern int indexModifier = 0; //number of frames between spawned beats and the onset which triggers spawning int indexIncrement = (bpm / beatList.Count); //fixed value between each beat float indexFloatFix = 0.0f; //a value that stores the remainder in case the bpm is not divisible into perfect frames foreach (int i in beatList) { //store the remaining part of the float because frames are ints, but bpm fractions are floats //if there is a remainder in excess of 1, decrement 1 from storage, and increment the index modifier by 1 indexFloatFix += Mathf.Repeat(((float)bpm / beatList.Count), 1.0f); if (indexFloatFix > 1.0f) { indexFloatFix -= 1.0f; indexModifier += 1; } //spawn the beat and increment the index modifier if (i == 1) { beats.Add(CreateBeat(onset.index + indexModifier)); indexModifier += indexIncrement; } // still increment the index modifer when there is no beat to be spawned else if (i == 0) { indexModifier += indexIncrement; } } } }
void Start() { Initialize(); beatPattern = GetComponent <BeatPattern>(); audioSource = GetComponent <AudioSource>(); }
public void PatternEmptyStringTest() { _beatPattern = new BeatPattern(999, ""); Assert.AreEqual(_beatPattern.PatternString, "1"); Assert.AreEqual(_beatPattern.CurrentTickIndex, 0); }
public void PatternOverMaxValuesTest() { _beatPattern = new BeatPattern(30, "10101010101010101010101010101010101010101010101010101"); Assert.AreEqual(_beatPattern.CurrentTickIndex, 0); Assert.AreEqual(_beatPattern.PatternString, "10101010101010101010"); Assert.AreEqual(_beatPattern.PatternString.Length, 20); }
public void PatternPreMaxValuesTest() { _beatPattern = new BeatPattern(18, "1010101010101010101"); Assert.AreEqual(_beatPattern.CurrentTickIndex, 0); Assert.AreEqual(_beatPattern.PatternString.Length, 19); }
void Start() { Initialize(); beatPattern = GetComponent <BeatPattern>(); audioSource = GetComponent <AudioSource>(); AudioProcessor processor = FindObjectOfType <AudioProcessor>(); processor.onBeat.AddListener(onBeatDetected); processor.onSpectrum.AddListener(onSpectrumDetected); }
public void PatternNextTickTest() { _beatPattern = new BeatPattern(0, "10101001100"); _beatPattern.NextTick(); _beatPattern.NextTick(); _beatPattern.NextTick(); _beatPattern.NextTick(); _beatPattern.NextTick(); _beatPattern.NextTick(); _beatPattern.NextTick(); Assert.AreEqual(_beatPattern.CurrentTickIndex, 7); Assert.AreEqual(_beatPattern.CurrentTick, '1'); }
public void PatternEmptyMeasureTest() { _beatPattern = new BeatPattern(0, ""); Assert.AreEqual(_beatPattern.Measure, "1/4"); }
public void PatternLargeMeasureTest() { _beatPattern = new BeatPattern(0, "100010001001"); Assert.AreEqual(_beatPattern.Measure, "12/4"); }
public void PatternMeasureTest() { _beatPattern = new BeatPattern(0, "1000"); Assert.AreEqual(_beatPattern.Measure, "4/4"); }
public void PatternBasicTest() { _beatPattern = new BeatPattern(0, "1000"); Assert.AreEqual(_beatPattern.PatternString, "1000"); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (property.propertyType == SerializedPropertyType.String) { string number = Regex.Replace(label.text, @"\D", ""); GUI.color = Color.green; Rect labelRect = new Rect(position.x, position.y, 300, 20); GUI.Label(labelRect, number); //setting the length of the string BeatPattern bp = attribute as BeatPattern; if (property.stringValue.Length != bp.patternLength) { StringBuilder startString = new StringBuilder(); for (int i = 0; i < bp.patternLength; i++) { startString.Append('0'); } property.stringValue = startString.ToString(); } StringBuilder sb = new StringBuilder(property.stringValue); for (int i = 0; i < property.stringValue.Length; i++) { Rect buttonRect = new Rect(position.x + 21 + (11 * i), position.y, 10, 20); //coloring if (sb[i] == '1') { GUI.color = Color.green; } else { if (i % bp.beatInterval == 0) { GUI.color = Color.red; } else { GUI.color = Color.black; } } if (GUI.Button(buttonRect, GUIContent.none)) { if (sb[i] == '0') { sb[i] = '1'; property.stringValue = sb.ToString(); } else { sb[i] = '0'; property.stringValue = sb.ToString(); } } } } else { GUI.color = Color.green; Rect labelRect = new Rect(position.x, position.y, 20, 20); GUI.Label(labelRect, "This attribute only works with strings"); } GUI.color = Color.white; }