-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpectrum.cs
126 lines (111 loc) · 5.07 KB
/
Spectrum.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using OpenTK;
using StorybrewCommon.Scripting;
using StorybrewCommon.Storyboarding;
using StorybrewCommon.Animations;
using System;
using static System.Math;
namespace StorybrewScripts
{
class Spectrum : StoryboardObjectGenerator
{
protected override void Generate()
{
// If you don't have the beatmap use ImportOsb
// CaptureVocals();
MakeSpectrum(48949, 65780);
MakeRadial(126740, 145926);
MakeSpectrum(151507, 173833);
MakeSpectrum(258251, 265926);
MakeSpectrum(268716, 275083);
}
void MakeSpectrum(int startTime, int endTime)
{
var bMap = GetMapsetBitmap("sb/pl.png");
var BarCount = 20;
var fftCount = BarCount * 2;
var scale = new Vector2(15, 150);
var basePos = new Vector2(-50, 470);
var keyframes = new KeyframedValue<float>[fftCount];
for (var i = 0; i < fftCount; i++) keyframes[i] = new KeyframedValue<float>();
var timeStep = Beatmap.GetTimingPointAt(startTime).BeatDuration / 8;
for (double time = startTime; time < endTime; time += timeStep)
{
var fft = GetFft(time, fftCount, null, OsbEasing.InExpo);
for (var i = 0; i < BarCount; i++)
{
var height = Pow(Log10(1 + fft[i] * 470), 1.6) * scale.Y / bMap.Height;
if (height < 1) height = 1;
keyframes[i].Add(time, (float)height);
}
}
var width = 780 / BarCount;
for (var i = 0; i < BarCount; i++)
{
var keyframe = keyframes[i];
keyframe.Simplify1dKeyframes(1.5, f => f);
var sprite = GetLayer("").CreateSprite("sb/pl.png", OsbOrigin.Centre, new Vector2(basePos.X + i * width, basePos.Y));
sprite.Fade(startTime, startTime + 500, 0, .5);
sprite.Fade(endTime, endTime + 500, .5, 0);
sprite.Additive(startTime);
var scaleX = (double)scale.X * width / bMap.Width; scaleX = Floor(scaleX * 10) / 10f;
var hasScale = false;
keyframe.ForEachPair((start, end) =>
{
hasScale = true;
sprite.ScaleVec(start.Time, end.Time, scaleX, start.Value, scaleX, end.Value);
}, 1);
if (!hasScale) sprite.ScaleVec(startTime, scaleX, 1);
}
}
void MakeRadial(int startTime, int endTime)
{
var BarCount = 28;
var fftCount = (int)(BarCount * 1.5);
var scale = new Vector2(7.5f, 200);
var Position = new Vector2(320, 240);
var radius = 125;
var height = new KeyframedValue<float>[fftCount];
for (var i = 0; i < fftCount; i++) height[i] = new KeyframedValue<float>();
var timeStep = Beatmap.GetTimingPointAt(startTime).BeatDuration / 6;
for (double t = startTime; t <= endTime + 10; t += timeStep)
{
var fft = GetFft(t, fftCount, null, OsbEasing.InExpo);
for (var i = 0; i < BarCount; i++)
{
var val = Log10(1 + fft[i] * 5) * scale.Y;
if (val < 1) val = 1;
height[i].Add(t, (float)val);
}
}
for (var i = 0; i < BarCount; i++)
{
var keyframe = height[i];
keyframe.Simplify1dKeyframes(5, h => h);
var bar = GetLayer("").CreateSprite("sb/px.png", OsbOrigin.BottomCentre, new Vector2(
(float)(Position.X + radius * Cos(i * 2 * PI / BarCount)),
(float)(Position.Y + radius * Sin(i * 2 * PI / BarCount))));
bar.Additive(startTime);
bar.Rotate(startTime, i * 2 * PI / BarCount + PI / 2);
bar.Fade(startTime, .75);
bar.Fade(endTime, endTime + 200, .75, 0);
keyframe.ForEachPair((s, e) => bar.ScaleVec(s.Time, e.Time, scale.X, s.Value, scale.X, e.Value), 1);
}
}
[Obsolete("Unused, represents code in ImportOsb script")] void CaptureVocals()
{
using (var pool = new SpritePool(GetLayer("ControlledSpec"), "sb/px.png", new Vector2(320, 240), (p, s, e) =>
{
p.Additive(s);
p.Color(s, 1, 0, 0);
}))
foreach (var hit in GetBeatmap("hitsound sb").HitObjects)
{
var beat = Beatmap.GetTimingPointAt(10000).BeatDuration;
var sprite = pool.Get(hit.StartTime, hit.EndTime + beat * 4);
sprite.ScaleVec(OsbEasing.OutQuint, hit.StartTime, hit.EndTime + beat * 2, 0, 50, 854, 50);
sprite.Rotate(OsbEasing.OutQuint, hit.StartTime, hit.EndTime + beat * 3, 0, Random(-PI / 30, PI / 30));
sprite.Fade(OsbEasing.Out, hit.StartTime, hit.EndTime + beat * 4, .3, 0);
}
}
}
}