Skip to content

Commit

Permalink
Fixed hispeed stuff
Browse files Browse the repository at this point in the history
Hispeed setting now mostly matches wacca hispeed.
hispeed gimmicks also show up in visual
hispeed setting also saves between launches
  • Loading branch information
Goatgarien committed Feb 15, 2023
1 parent 679ca8c commit 89db842
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 59 deletions.
14 changes: 9 additions & 5 deletions BAKKA-Editor/Chart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,14 @@ public void RecalcTime()
TimeEvents[0].StartTime = Offset * 1000.0;
for (int i = 1; i < TimeEvents.Count; i++)
{
TimeEvents[i].StartTime = ((TimeEvents[i].Measure - TimeEvents[i - 1].Measure) * 4 * TimeEvents[i - 1].TimeSig.Ratio * (60000.0 / TimeEvents[i].BPM)) + TimeEvents[i - 1].StartTime;
TimeEvents[i].StartTime = ((TimeEvents[i].Measure - TimeEvents[i - 1].Measure) * (4.0f * TimeEvents[i - 1].TimeSig.Ratio * (60000.0 / TimeEvents[i - 1].BPM))) + TimeEvents[i - 1].StartTime;
}
}

/*
((60000.0 / evt.BPM) * 4.0 * evt.TimeSig.Ratio) * measure = time
time / ((60000.0 / evt.BPM) * 4.0 * evt.TimeSig.Ratio) = measure
*/

/// <summary>
/// Translate clock time to beats
/// </summary>
Expand All @@ -274,7 +278,7 @@ public BeatInfo GetBeat(float time)
var evt = TimeEvents.Where(x => time >= x.StartTime).LastOrDefault();
if (evt == null)
evt = TimeEvents[0];
return new BeatInfo((float)(evt.BPM * (time - evt.StartTime) / (60000.0f * evt.TimeSig.Ratio * 4)) + evt.Measure);
return new BeatInfo((float)((time - evt.StartTime) / ((60000.0 / evt.BPM) * 4.0f * evt.TimeSig.Ratio) + evt.Measure));
}

/// <summary>
Expand All @@ -290,7 +294,7 @@ public int GetTime(BeatInfo beat)
var evt = TimeEvents.Where(x => beat.MeasureDecimal >= x.Measure).LastOrDefault();
if (evt == null)
evt = TimeEvents[0];
return (int)((60000.0 * 4.0 * evt.TimeSig.Ratio / evt.BPM) * (beat.MeasureDecimal - evt.Measure) + evt.StartTime);
return (int)(((60000.0 / evt.BPM) * 4.0f * evt.TimeSig.Ratio) * (beat.MeasureDecimal - evt.Measure) + evt.StartTime);
}
}
}
}
69 changes: 42 additions & 27 deletions BAKKA-Editor/CircleView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;
using System.Drawing.Drawing2D;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;

namespace BAKKA_Editor
{
Expand All @@ -15,10 +16,7 @@ internal class CircleView
public PointF CenterPoint { get; private set; }
public float Radius { get; private set; }
public float CurrentMeasure { get; set; }
/// <summary>
/// Number of measures in the future that are visible
/// </summary>
public float TotalMeasureShowNotes { get; set; } = 0.5f;
public float Hispeed { get; set; } = 1.5f;

// Pens and Brushes
public Pen BasePen { get; set; }
Expand Down Expand Up @@ -74,10 +72,27 @@ public void Update(SizeF size)
FlairPen = new Pen(Color.FromArgb(FlairTransparency, Color.Yellow), PanelSize.Width * 8.0f / 600.0f);
}

private ArcInfo GetScaledRect(float objectTime)
private float GetTotalMeasureShowNotes(Chart chart)
{
//Convert hispeed to frames
float displayFrames = 73.0f - ((Hispeed - 1.5f) * 10.0f);
//Account for hispeed gimmick
var LatestHispeedChange = chart.Gimmicks.Where(x => x.GimmickType == GimmickType.HiSpeedChange && CurrentMeasure >= x.Measure).LastOrDefault();
if (LatestHispeedChange != null)
{
displayFrames = displayFrames / (float)LatestHispeedChange.HiSpeed;
}
//Add frame time to current time
float EndTimeDisplay = chart.GetTime(new BeatInfo(CurrentMeasure)) + ((displayFrames / 60.0f) * 1000.0f);
//convert time back to a measureDecimal
BeatInfo EndMeasure = chart.GetBeat(EndTimeDisplay);
return EndMeasure.MeasureDecimal - CurrentMeasure;
}

private ArcInfo GetScaledRect(Chart chart, float objectTime)
{
ArcInfo info = new();
float notescaleInit = 1 - ((objectTime - CurrentMeasure) * (1 / TotalMeasureShowNotes)); // Scale from 0-1
float notescaleInit = 1 - ((objectTime - CurrentMeasure) * (1 / GetTotalMeasureShowNotes(chart))); // Scale from 0-1
info.NoteScale = (float)Math.Pow(10.0f, notescaleInit) / 10.0f;
float scaledRectSize = DrawRect.Width * info.NoteScale;
float scaledRadius = scaledRectSize / 2.0f;
Expand All @@ -89,9 +104,9 @@ private ArcInfo GetScaledRect(float objectTime)
return info;
}

private ArcInfo GetArcInfo(Note note)
private ArcInfo GetArcInfo(Chart chart, Note note)
{
ArcInfo info = GetScaledRect(note.Measure);
ArcInfo info = GetScaledRect(chart, note.Measure);
info.StartAngle = -note.Position * 6;
info.ArcLength = -note.Size * 6;
if(info.ArcLength != -360)
Expand Down Expand Up @@ -191,15 +206,15 @@ public void DrawMasks(Chart chart)
}
}

public void DrawCircle()
public void DrawCircle(Chart chart)
{
// Switch drawing modes
bufGraphics.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

// Draw measure circle
for (float meas = (float)Math.Ceiling(CurrentMeasure); (meas - CurrentMeasure) < TotalMeasureShowNotes; meas += 1.0f)
for (float meas = (float)Math.Ceiling(CurrentMeasure); (meas - CurrentMeasure) < GetTotalMeasureShowNotes(chart); meas += 1.0f)
{
var info = GetScaledRect(meas);
var info = GetScaledRect(chart, meas);
if (info.Rect.Width >= 1)
{
bufGraphics.Graphics.DrawEllipse(BeatPen, info.Rect);
Expand Down Expand Up @@ -248,11 +263,11 @@ public void DrawGimmicks(Chart chart, bool showGimmicks, int selectedGimmickInde
{
List<Gimmick> drawGimmicks = chart.Gimmicks.Where(
x => x.Measure >= CurrentMeasure
&& x.Measure <= (CurrentMeasure + TotalMeasureShowNotes)).ToList();
&& x.Measure <= (CurrentMeasure + GetTotalMeasureShowNotes(chart))).ToList();

foreach (var gimmick in drawGimmicks)
{
var info = GetScaledRect(gimmick.Measure);
var info = GetScaledRect(chart, gimmick.Measure);

if (info.Rect.Width >= 1)
{
Expand All @@ -264,19 +279,19 @@ public void DrawGimmicks(Chart chart, bool showGimmicks, int selectedGimmickInde

public void DrawHolds(Chart chart, bool highlightSelectedNote, int selectedNoteIndex)
{
ArcInfo currentInfo = GetScaledRect(CurrentMeasure);
ArcInfo endInfo = GetScaledRect(CurrentMeasure + TotalMeasureShowNotes);
ArcInfo currentInfo = GetScaledRect(chart, CurrentMeasure);
ArcInfo endInfo = GetScaledRect(chart, CurrentMeasure + GetTotalMeasureShowNotes(chart));

// First, draw holes that start before the viewpoint and have nodes that end after
List<Note> holdNotes = chart.Notes.Where(
x => x.Measure < CurrentMeasure
&& x.NextNote != null
&& x.NextNote.Measure > (CurrentMeasure + TotalMeasureShowNotes)
&& x.NextNote.Measure > (CurrentMeasure + GetTotalMeasureShowNotes(chart))
&& x.IsHold).ToList();
foreach (var note in holdNotes)
{
ArcInfo info = GetArcInfo(note);
ArcInfo nextInfo = GetArcInfo((Note)note.NextNote);
ArcInfo info = GetArcInfo(chart, note);
ArcInfo nextInfo = GetArcInfo(chart, (Note)note.NextNote);
//GraphicsPath path = new GraphicsPath();
//path.AddArc(endInfo.Rect, info.StartAngle, info.ArcLength);
//path.AddArc(currentInfo.Rect, info.StartAngle + info.ArcLength, -info.ArcLength);
Expand Down Expand Up @@ -323,16 +338,16 @@ public void DrawHolds(Chart chart, bool highlightSelectedNote, int selectedNoteI
// Second, draw all the notes on-screen
holdNotes = chart.Notes.Where(
x => x.Measure >= CurrentMeasure
&& x.Measure <= (CurrentMeasure + TotalMeasureShowNotes)
&& x.Measure <= (CurrentMeasure + GetTotalMeasureShowNotes(chart))
&& x.IsHold).ToList();
foreach (var note in holdNotes)
{
ArcInfo info = GetArcInfo(note);
ArcInfo info = GetArcInfo(chart, note);

// If the previous note is off-screen, this case handles that
if (note.PrevNote != null && note.PrevNote.Measure < CurrentMeasure)
{
ArcInfo prevInfo = GetArcInfo((Note)note.PrevNote);
ArcInfo prevInfo = GetArcInfo(chart, (Note)note.PrevNote);
float ratio = (currentInfo.Rect.Width - info.Rect.Width) / (prevInfo.Rect.Width - info.Rect.Width);
float startNoteAngle = info.StartAngle;
float endNoteAngle = prevInfo.StartAngle;
Expand All @@ -356,19 +371,19 @@ public void DrawHolds(Chart chart, bool highlightSelectedNote, int selectedNoteI
}

// If the next note is on-screen, this case handles that
if (note.NextNote != null && note.NextNote.Measure <= (CurrentMeasure + TotalMeasureShowNotes))
if (note.NextNote != null && note.NextNote.Measure <= (CurrentMeasure + GetTotalMeasureShowNotes(chart)))
{
ArcInfo nextInfo = GetArcInfo((Note)note.NextNote);
ArcInfo nextInfo = GetArcInfo(chart, (Note)note.NextNote);
GraphicsPath path = new GraphicsPath();
path.AddArc(info.Rect, info.StartAngle, info.ArcLength);
path.AddArc(nextInfo.Rect, nextInfo.StartAngle + nextInfo.ArcLength, -nextInfo.ArcLength);
bufGraphics.Graphics.FillPath(HoldBrush, path);
}

// If the next note is off-screen, this case handles that
if (note.NextNote != null && note.NextNote.Measure > (CurrentMeasure + TotalMeasureShowNotes))
if (note.NextNote != null && note.NextNote.Measure > (CurrentMeasure + GetTotalMeasureShowNotes(chart)))
{
ArcInfo nextInfo = GetArcInfo((Note)note.NextNote);
ArcInfo nextInfo = GetArcInfo(chart, (Note)note.NextNote);
float ratio = (endInfo.Rect.Width - nextInfo.Rect.Width) / (info.Rect.Width - nextInfo.Rect.Width);
float startNoteAngle = nextInfo.StartAngle;
float endNoteAngle = info.StartAngle;
Expand Down Expand Up @@ -416,11 +431,11 @@ public void DrawNotes(Chart chart, bool highlightSelectedNote, int selectedNoteI
{
List<Note> drawNotes = chart.Notes.Where(
x => x.Measure >= CurrentMeasure
&& x.Measure <= (CurrentMeasure + TotalMeasureShowNotes)
&& x.Measure <= (CurrentMeasure + GetTotalMeasureShowNotes(chart))
&& !x.IsHold && !x.IsMask).ToList();
foreach (var note in drawNotes)
{
ArcInfo info = GetArcInfo(note);
ArcInfo info = GetArcInfo(chart, note);

if (info.Rect.Width >= 1)
{
Expand Down
36 changes: 19 additions & 17 deletions BAKKA-Editor/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions BAKKA-Editor/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public MainForm()
highlightViewedNoteToolStripMenuItem.Checked = userSettings.ViewSettings.HighlightViewedNote;
showGimmicksInCircleViewToolStripMenuItem.Checked = userSettings.ViewSettings.ShowGimmicks;
selectLastInsertedNoteToolStripMenuItem.Checked = userSettings.ViewSettings.SelectLastInsertedNote;
visualHispeedNumeric.Value = (decimal)userSettings.ViewSettings.HispeedSetting;
autoSaveTimer.Interval = userSettings.SaveSettings.AutoSaveInterval * 60000;
autoSaveTimer.Enabled = true;
// Update hotkey labels
Expand Down Expand Up @@ -352,6 +353,7 @@ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
userSettings.ViewSettings.HighlightViewedNote = highlightViewedNoteToolStripMenuItem.Checked;
userSettings.ViewSettings.ShowGimmicks = showGimmicksInCircleViewToolStripMenuItem.Checked;
userSettings.ViewSettings.SelectLastInsertedNote = selectLastInsertedNoteToolStripMenuItem.Checked;
userSettings.ViewSettings.HispeedSetting = circleView.Hispeed;
userSettings.SaveSettings.AutoSaveInterval = autoSaveTimer.Interval / 60000;
//Update user settings.toml
if (File.Exists("settings.toml"))
Expand Down Expand Up @@ -540,7 +542,7 @@ private void circlePanel_Paint(object sender, PaintEventArgs e)
circleView.DrawMasks(chart);

// Draw base and measure circle.
circleView.DrawCircle();
circleView.DrawCircle(chart);

// Draw degree lines
circleView.DrawDegreeLines();
Expand Down Expand Up @@ -975,6 +977,8 @@ private void selectSongButton_Click(object sender, EventArgs e)
songTrackBar.Value = 0;
songTrackBar.Maximum = (int)currentSong.PlayLength;
playButton.Enabled = true;
measureNumeric.Value = 0;
beat1Numeric.Value = 0;
}
}
}
Expand Down Expand Up @@ -1022,14 +1026,6 @@ private void updateTimer_Tick(object sender, EventArgs e)
measureNumeric.Value = info.Measure;
beat1Numeric.Value = (int)((float)info.Beat / 1920.0f * (float)beat2Numeric.Value);
circleView.CurrentMeasure = info.MeasureDecimal;

// TODO Fix hi-speed (it needs to be able to display multiple hi-speeds in the circle view at once)
//// Change hi-speed, if applicable
//var hispeed = chart.Gimmicks.Where(x => x.Measure <= info.Measure && x.GimmickType == GimmickType.HiSpeedChange).LastOrDefault();
//if (hispeed != null && hispeed.HiSpeed != circleView.TotalMeasureShowNotes)
//{
// visualHispeedNumeric.Value = (decimal)hispeed.HiSpeed;
//}
}
circlePanel.Invalidate();
}
Expand Down Expand Up @@ -1126,7 +1122,7 @@ private void circlePanel_MouseMove(object sender, MouseEventArgs e)

private void visualHispeedNumeric_ValueChanged(object sender, EventArgs e)
{
circleView.TotalMeasureShowNotes = (float)visualHispeedNumeric.Value;
circleView.Hispeed = (float)visualHispeedNumeric.Value;
circlePanel.Invalidate();
}

Expand Down
Loading

0 comments on commit 89db842

Please sign in to comment.