public void OnUpdate() { if (paused) { return; } songPosition = (float)(AudioSettings.dspTime - dspTimeSong) * m_AudioService.GetAudioSource().pitch; float beatToShow = songPosition / crotchet + BeatsShownOnScreen; for (int i = 0; i < len; i++) { int nextIndex = trackNextIndices[i]; SongInfo.Track currTrack = tracks[i]; if (nextIndex < currTrack.Notes.Length && currTrack.Notes[nextIndex].note < beatToShow) { SongInfo.Note currNote = currTrack.Notes[nextIndex]; Vector3 parentPos = i == 0 ? LeftParent.position : RightParent.position; MusicNode musicNode = Instantiate(NodePrefab, new Vector3(parentPos.x, Screen.height + 200, 0), this.transform.rotation, i == 0 ? LeftParent : RightParent); musicNode.Initialize(parentPos.x, Screen.height + 200, finishLineY, 0, currNote.note); trackNextIndices[i]++; queueForTracks[i].Enqueue(musicNode); } } if (songPosition > songLength) { if (m_OnFinish != null) { m_OnFinish.Invoke(); paused = true; m_OnFinish = null; m_OnInput = null; } } }
void Update() { //for count down if (!songStarted) { return; } //for pausing if (paused) { if (pauseTimeStamp < 0f) //not managed { pauseTimeStamp = (float)AudioSettings.dspTime; //print("pausetimestamp:" + pauseTimeStamp.ToString()); audioSource.Pause(); } return; } else if (pauseTimeStamp > 0f) //resume not managed { pausedTime += (float)AudioSettings.dspTime - pauseTimeStamp; //print("resumetimestamp:"+AudioSettings.dspTime.ToString()); //print("offset"+pausedTime.ToString()); audioSource.Play(); pauseTimeStamp = -1f; } //calculate songposition songposition = (float)(AudioSettings.dspTime - dsptimesong - pausedTime) * audioSource.pitch - songInfo.songOffset; //print (songposition); //check if need to instantiate new nodes float beatToShow = songposition / crotchet + BeatsShownOnScreen; //loop the tracks for new MusicNodes for (int i = 0; i < len; i++) { int nextIndex = trackNextIndices[i]; SongInfo.Track currTrack = tracks[i]; if (nextIndex < currTrack.notes.Length && currTrack.notes[nextIndex].note < beatToShow) { SongInfo.Note currNote = currTrack.notes[nextIndex]; //set z position float layerZ = nextLayerZ[i]; nextLayerZ[i] += LayerOffsetZ; //get a new node MusicNode musicNode = MusicNodePool.instance.GetNode(trackSpawnPosX[i], startLineY, finishLineY, removeLineY, layerZ, currNote.note, currNote.times, trackColors[i]); //enqueue queueForTracks[i].Enqueue(musicNode); //update the next index trackNextIndices[i]++; } } //loop the queue to check if any of them reaches the finish line for (int i = 0; i < len; i++) { //empty queue, continue if (queueForTracks[i].Count == 0) { continue; } MusicNode currNode = queueForTracks[i].Peek(); //multi-times note if (currNode.times > 0 && currNode.transform.position.y <= finishLineY + goodOffsetY) { //have previous note stuck on the finish line if (previousMusicNodes[i] != null) { previousMusicNodes[i].MultiTimesFailed(); //dispatch miss event if (beatOnHitEvent != null) { beatOnHitEvent(i, Rank.MISS); } } //pause the note currNode.paused = true; //align to finish line currNode.transform.position = new Vector3(currNode.transform.position.x, finishLineY, currNode.transform.position.z); //deque, but keep a reference previousMusicNodes[i] = currNode; queueForTracks[i].Dequeue(); } else if (currNode.transform.position.y <= finishLineY - goodOffsetY) //single time note { //have previous note stuck on the finish line if (previousMusicNodes[i] != null) { previousMusicNodes[i].MultiTimesFailed(); previousMusicNodes[i] = null; //dispatch miss event if (beatOnHitEvent != null) { beatOnHitEvent(i, Rank.MISS); } } //deque queueForTracks[i].Dequeue(); //dispatch miss event (if a multi-times note is missed, its next single note would also be missed) if (beatOnHitEvent != null) { beatOnHitEvent(i, Rank.MISS); } } } //check to see if the song reaches its end if (songposition > songLength) { songStarted = false; if (songCompletedEvent != null) { songCompletedEvent(); } } }
protected override void OnPaint(PaintEventArgs e) { solidBrush.Color = Theme.PlayerColor; e.Graphics.FillRectangle(solidBrush, e.ClipRectangle); e.Graphics.DrawString(Strings.PlayerPosition, Font, Brushes.Lime, positionX, infoY); e.Graphics.DrawString(Strings.PlayerRest, Font, Brushes.Crimson, delayX, infoY); e.Graphics.DrawString(Strings.PlayerNotes, Font, Brushes.Turquoise, keysX, infoY); e.Graphics.DrawString("L", Font, Brushes.GreenYellow, barStartX - 5, infoY); e.Graphics.DrawString(string.Format("{0} - ", Strings.PlayerTempo) + Info.Tempo, Font, Brushes.Cyan, tempoX, infoY); e.Graphics.DrawString("R", Font, Brushes.GreenYellow, barRightBoundX - 5, infoY); e.Graphics.DrawString(Strings.PlayerType, Font, Brushes.DeepPink, typeX, infoY); e.Graphics.DrawLine(Pens.Gold, 0, infoHeight, Width, infoHeight); for (int i = 0; i < numTracksToDraw; i++) { SongInfo.Track track = Info.Tracks[i]; float r1y = infoHeight + yMargin + (i * trackHeight); // Row 1 y e.Graphics.DrawString(string.Format("0x{0:X}", track.Position), Font, Brushes.Lime, positionX, r1y); e.Graphics.DrawString(track.Rest.ToString(), Font, Brushes.Crimson, delayX, r1y); float r2y = r1y + row2Offset; // Row 2 y e.Graphics.DrawString(track.Panpot.ToString(), Font, Brushes.OrangeRed, voicesX + row2ElementAdditionX, r2y); e.Graphics.DrawString(track.Volume.ToString(), Font, Brushes.LightSeaGreen, voicesX + (row2ElementAdditionX * 2), r2y); e.Graphics.DrawString(track.LFO.ToString(), Font, Brushes.SkyBlue, voicesX + (row2ElementAdditionX * 3), r2y); e.Graphics.DrawString(track.PitchBend.ToString(), Font, Brushes.Purple, voicesX + (row2ElementAdditionX * 4), r2y); e.Graphics.DrawString(track.Extra.ToString(), Font, Brushes.HotPink, voicesX + (row2ElementAdditionX * 5), r2y); int by = (int)(r1y + yMargin); // Bar y int byh = by + barHeight; e.Graphics.DrawString(track.Type, Font, Brushes.DeepPink, typeEndX - e.Graphics.MeasureString(track.Type, Font).Width, by + (row2Offset / (Font.Size / 2.5f))); e.Graphics.DrawLine(Pens.GreenYellow, barStartX, by, barStartX, byh); // Left bar bound line e.Graphics.DrawLine(Pens.GreenYellow, barRightBoundX, by, barRightBoundX, byh); // Right bar bound line if (GlobalConfig.Instance.PanpotIndicators) { int pax = (int)(barStartX + (barWidth / 2) + (barWidth / 2 * (track.Panpot / (float)0x40))); // Pan line x e.Graphics.DrawLine(Pens.OrangeRed, pax, by, pax, byh); // Pan line } { Color color = GlobalConfig.Instance.Colors[track.Voice]; solidBrush.Color = color; pen.Color = color; e.Graphics.DrawString(track.Voice.ToString(), Font, solidBrush, voicesX, r2y); var rect = new Rectangle((int)(barStartX + (barWidth / 2) - (track.LeftVolume * barWidth / 2)) + bwd, by, (int)((track.LeftVolume + track.RightVolume) * barWidth / 2), barHeight); if (!rect.IsEmpty) { float velocity = (track.LeftVolume + track.RightVolume) * 2f; if (velocity > 1f) { velocity = 1f; } solidBrush.Color = Color.FromArgb((byte)(velocity * byte.MaxValue), color); e.Graphics.FillRectangle(solidBrush, rect); e.Graphics.DrawRectangle(pen, rect); } if (GlobalConfig.Instance.CenterIndicators) { e.Graphics.DrawLine(pen, barCenterX, by, barCenterX, byh); // Center line } } { string keysString; if (track.Keys[0] == byte.MaxValue) { if (track.PreviousKeysTime != 0) { track.PreviousKeysTime--; keysString = track.PreviousKeys; } else { keysString = string.Empty; } } else { keysString = string.Empty; for (int nk = 0; nk < SongInfo.MaxKeys; nk++) { byte k = track.Keys[nk]; if (k == byte.MaxValue) { break; } else { if (nk != 0) { keysString += ' '; } keysString += Utils.GetNoteName(k); } } track.PreviousKeysTime = GlobalConfig.Instance.RefreshRate << 2; track.PreviousKeys = keysString; } if (keysString != string.Empty) { e.Graphics.DrawString(keysString, Font, Brushes.Turquoise, keysX, r1y); } } } base.OnPaint(e); }
// Update is called once per frame void Update() { if (!songStarted) { return; } if (paused) { if (pauseTimeStamp < 0f) { pauseTimeStamp = (float)AudioSettings.dspTime; song.Pause(); } return; } else if (pauseTimeStamp > 0f) { pausedTime += (float)AudioSettings.dspTime - pauseTimeStamp; song.Play(); pauseTimeStamp = -1f; } songPosition = (float)(AudioSettings.dspTime - dspTimeSong - pausedTime) * song.pitch - songInfo.songOffset; songPosInBeats = songPosition / secPerBeat; // check if we need to instantiate new prefabs of notes float notesToShow = (songPosition / secPerBeat) + beatsShownOnScreen; // for loop to iterate through the tracks to spawn more music notes for (int i = 0; i < length; i++) { int nextIndex = trackNextIndices[i]; SongInfo.Track currentTrack = tracks[i]; if (nextIndex < currentTrack.notes.Length && currentTrack.notes[nextIndex].note < notesToShow) { SongInfo.Note currentNote = currentTrack.notes[nextIndex]; MusicNoteController musicNote = MusicNotePool.instance.CreateAndGetNote(spawnPosX[i], startPosY, endPosY, removePosY, 0, currentNote.note); queueForTracks[i].Enqueue(musicNote); trackNextIndices[i]++; } } // loop the queue to check if any of the notes reached the finish line for (int i = 0; i < length; i++) { if (queueForTracks[i].Count == 0) { continue; } MusicNoteController currentNote = queueForTracks[i].Peek(); if (currentNote.transform.position.y <= endPosY - goodRankYEnd) { queueForTracks[i].Dequeue(); if (onHitEvent != null) { onHitEvent(i, Rank.MISS); } } } if (songPosition > songLength) { songStarted = false; if (songCompletedEvent != null) { songCompletedEvent(); } } }
private void Update() { if (Input.GetKeyDown("p"))///////////////////////////////////// { FireBall(); } if (!ConductorCustom.Instance.paused) { //check if need to instantiate new nodes float beatToShow = ConductorCustom.songposition / ConductorCustom.crotchet + ConductorCustom.BeatsShownOnScreen; for (int i = 0; i < queueForTracks.Length; i++) { int nextIndex = trackNextIndices[i]; SongInfo.Track currTrack = tracksNode[i]; if (nextIndex < currTrack.notes.Length && currTrack.notes[nextIndex].note < beatToShow) { SongInfo.Note currNote = currTrack.notes[nextIndex]; //set z position float layerZ = nextLayerZ[i]; nextLayerZ[i] += LayerOffsetZ; //get a new node MusicNode musicNode = MusicNodePool.instance.GetNode(tracks[i].offsetX, partitionManager.startLineY, partitionManager.finishLineY, partitionManager.removeLineY, layerZ, currNote.note, currNote.times, TracksColors[i], idplayer); if (nextNoteIsStone) { musicNode.isStone = true; nextNoteIsStone = false; } //enqueue queueForTracks[i].Enqueue(musicNode); //update the next index trackNextIndices[i]++; } } for (int i = 0; i < queueForTracks.Length; i++) { //empty queue, continue if (queueForTracks[i].Count == 0) { continue; } MusicNode currNode = queueForTracks[i].Peek(); //multi-times note if (currNode.transform.position.y <= partitionManager.finishLineY - partitionManager.badOffsetY) //single time note { //have previous note stuck on the finish line if (previousMusicNodes[i] != null) { previousMusicNodes[i].MultiTimesFailed(); previousMusicNodes[i] = null; //dispatch miss event if (beatOnHitEvent != null) { beatOnHitEvent(i, PartitionManager.Rank.MISS); } } //deque queueForTracks[i].Dequeue(); //dispatch miss event (if a multi-times note is missed, its next single note would also be missed) if (beatOnHitEvent != null) { beatOnHitEvent(i, PartitionManager.Rank.MISS); } } } } }