mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-13 08:27:37 +02:00
Expose Song Pitch to Minigames (#301)
* expose song pitch to minigames * clean up new additions * make new functions actually set music pitch * fix playback speed slider bug
This commit is contained in:
@ -17,7 +17,7 @@ namespace HeavenStudio
|
|||||||
public float secPerBeat;
|
public float secPerBeat;
|
||||||
|
|
||||||
// The number of seconds for each song beat, inversely scaled to song pitch (higer pitch = shorter time)
|
// The number of seconds for each song beat, inversely scaled to song pitch (higer pitch = shorter time)
|
||||||
public float pitchedSecPerBeat => (secPerBeat / musicSource.pitch);
|
public float pitchedSecPerBeat => (secPerBeat / SongPitch);
|
||||||
|
|
||||||
// Current song position, in seconds
|
// Current song position, in seconds
|
||||||
private double songPos; // for Conductor use only
|
private double songPos; // for Conductor use only
|
||||||
@ -64,11 +64,23 @@ namespace HeavenStudio
|
|||||||
public bool metronome = false;
|
public bool metronome = false;
|
||||||
Util.Sound metronomeSound;
|
Util.Sound metronomeSound;
|
||||||
|
|
||||||
public float timeSinceLastTempoChange = Single.MinValue;
|
// pitch values
|
||||||
|
private float timelinePitch = 1f;
|
||||||
|
private float minigamePitch = 1f;
|
||||||
|
public float SongPitch { get => timelinePitch * minigamePitch; }
|
||||||
|
|
||||||
private bool beat;
|
public void SetTimelinePitch(float pitch)
|
||||||
|
{
|
||||||
|
timelinePitch = pitch;
|
||||||
|
musicSource.pitch = SongPitch;
|
||||||
|
}
|
||||||
|
|
||||||
// private AudioDspTimeKeeper timeKeeper;
|
public void SetMinigamePitch(float pitch)
|
||||||
|
{
|
||||||
|
minigamePitch = pitch;
|
||||||
|
musicSource.pitch = SongPitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Awake()
|
void Awake()
|
||||||
{
|
{
|
||||||
@ -130,7 +142,7 @@ namespace HeavenStudio
|
|||||||
if (musicStartTime < 0f)
|
if (musicStartTime < 0f)
|
||||||
{
|
{
|
||||||
musicSource.time = (float) startPos;
|
musicSource.time = (float) startPos;
|
||||||
musicSource.PlayScheduled(AudioSettings.dspTime - firstBeatOffset / musicSource.pitch);
|
musicSource.PlayScheduled(AudioSettings.dspTime - firstBeatOffset / SongPitch);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -185,7 +197,7 @@ namespace HeavenStudio
|
|||||||
if (isPlaying)
|
if (isPlaying)
|
||||||
{
|
{
|
||||||
double absTime = Time.realtimeSinceStartupAsDouble;
|
double absTime = Time.realtimeSinceStartupAsDouble;
|
||||||
double dt = (absTime - lastAbsTime) * musicSource.pitch;
|
double dt = (absTime - lastAbsTime) * SongPitch;
|
||||||
lastAbsTime = absTime;
|
lastAbsTime = absTime;
|
||||||
|
|
||||||
time += dt;
|
time += dt;
|
||||||
|
@ -900,11 +900,12 @@ namespace HeavenStudio.Editor.Track
|
|||||||
return LayersRect.rect.height / 5f;
|
return LayersRect.rect.height / 5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const float SpeedSnap = 0.25f;
|
||||||
public void SetPlaybackSpeed(float speed)
|
public void SetPlaybackSpeed(float speed)
|
||||||
{
|
{
|
||||||
float spd = Mathp.Round2Nearest(speed, Timeline.SnapInterval());
|
float spd = Mathp.Round2Nearest(speed, SpeedSnap);
|
||||||
PlaybackSpeed.transform.GetChild(3).GetComponent<TMP_Text>().text = $"Playback Speed: {spd}x";
|
PlaybackSpeed.transform.GetChild(3).GetComponent<TMP_Text>().text = $"Playback Speed: {spd}x";
|
||||||
Conductor.instance.musicSource.pitch = spd;
|
Conductor.instance.SetTimelinePitch(spd);
|
||||||
PlaybackSpeed.value = spd;
|
PlaybackSpeed.value = spd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -914,6 +915,7 @@ namespace HeavenStudio.Editor.Track
|
|||||||
{
|
{
|
||||||
PlaybackSpeed.transform.GetChild(3).GetComponent<TMP_Text>().text = $"Playback Speed: 1x";
|
PlaybackSpeed.transform.GetChild(3).GetComponent<TMP_Text>().text = $"Playback Speed: 1x";
|
||||||
PlaybackSpeed.value = 1f;
|
PlaybackSpeed.value = 1f;
|
||||||
|
Conductor.instance.SetTimelinePitch(PlaybackSpeed.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ namespace HeavenStudio.Util
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
playInstant = false;
|
playInstant = false;
|
||||||
scheduledPitch = cnd.musicSource.pitch;
|
scheduledPitch = cnd.SongPitch;
|
||||||
startTime = (AudioSettings.dspTime + (cnd.GetSongPosFromBeat(beat) - cnd.songPositionAsDouble)/(double)scheduledPitch);
|
startTime = (AudioSettings.dspTime + (cnd.GetSongPosFromBeat(beat) - cnd.songPositionAsDouble)/(double)scheduledPitch);
|
||||||
audioSource.PlayScheduled(startTime);
|
audioSource.PlayScheduled(startTime);
|
||||||
}
|
}
|
||||||
@ -79,9 +79,9 @@ namespace HeavenStudio.Util
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!played && scheduledPitch != cnd.musicSource.pitch)
|
if (!played && scheduledPitch != cnd.SongPitch)
|
||||||
{
|
{
|
||||||
scheduledPitch = cnd.musicSource.pitch;
|
scheduledPitch = cnd.SongPitch;
|
||||||
startTime = (AudioSettings.dspTime + (cnd.GetSongPosFromBeat(beat) - cnd.songPositionAsDouble)/(double)scheduledPitch);
|
startTime = (AudioSettings.dspTime + (cnd.GetSongPosFromBeat(beat) - cnd.songPositionAsDouble)/(double)scheduledPitch);
|
||||||
audioSource.SetScheduledStartTime(startTime);
|
audioSource.SetScheduledStartTime(startTime);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user