/// <summary> /// Palauttaa kappaleessa tapahtuneet muutokset edelliseen päivitykseen nähden. /// </summary> /// <returns></returns> public SongState Update() { SongState state = new SongState(false, MelodyChange.None, false); if (currentBeatIndex < beatMoments.Length) { state.IsBeat = SecondsPlayed > beatMoments[currentBeatIndex]; if (state.IsBeat) currentBeatIndex++; } if (currentOnsetIndex < onsetMoments.Length) { bool newOnset = SecondsPlayed > onsetMoments[currentOnsetIndex]; if (newOnset) { state.IsOnset = true; // currentOnsetIndex++; /*float frequencyOnPreviousOnset = frequencies[currentFrequencyIndex]; int bComplementIndex = Array.BinarySearch(frequencyMoments, SecondsPlayed); if (bComplementIndex < 0) { // ei suoraa osumaa, indeksi on seuraavaksi suuremman arvon indeksin bitwise complement // (https://msdn.microsoft.com/en-us/library/2cy9f6wb.aspx) bComplementIndex = ~bComplementIndex; // ~ on bitwise complement -operaattori } currentFrequencyIndex = bComplementIndex; currentOnsetIndex++; // skipataan osa, sama binaryhaku tähän float currentFrequency = frequencies[currentFrequencyIndex]; */ // jos taajuus +- 1/4 sävelaskeleen sisällä edellisestä, sama nuotti uudestaan // jos yli 1/4, ylempi // jos alle 1/4, alempi float frequencyOnPreviousOnset; if (currentOnsetIndex - 1 >= 0) frequencyOnPreviousOnset = onsetFrequencies[currentOnsetIndex - 1]; else frequencyOnPreviousOnset = 0; float currentFrequency = onsetFrequencies[currentOnsetIndex]; currentOnsetIndex++; // ei ihan tarkka, mutta close enough i think float quarterStepDownChange = (frequencyOnPreviousOnset - (frequencyOnPreviousOnset / HALF_STEP_FREQUENCY_CHANGE)); float quarterStepUpChange = ((frequencyOnPreviousOnset * HALF_STEP_FREQUENCY_CHANGE) - frequencyOnPreviousOnset); if (currentFrequency > frequencyOnPreviousOnset + quarterStepUpChange) { state.Change = MelodyChange.HigherNote; return state; } if (currentFrequency < frequencyOnPreviousOnset - quarterStepDownChange) { state.Change = MelodyChange.LowerNote; return state; } state.Change = MelodyChange.SameNote; } } return state; }
void SongUpdate(SongState state, KeyboardChange keyChange) { if (state.IsBeat) { CreateShardPolygon(RandomGen.NextFloat(SPMinRadius, SPMaxRadius), RandomGen.NextFloat(SPMinSpeed, SPMaxSpeed)); } switch (state.Change) { case MelodyChange.None: break; case MelodyChange.SameNote: // testPoly.Position += new Vector2(25.0f, 0.0f); break; case MelodyChange.HigherNote: testPoly.Position += new Vector2(0.0f, -25.0f); break; case MelodyChange.LowerNote: testPoly.Position += new Vector2(0.0f, 25.0f); break; default: break; } if (state.IsOnset) { } }