Skip to content

Commit d481f5f

Browse files
committed
post add song + move code around
1 parent 54cf14d commit d481f5f

4 files changed

Lines changed: 51 additions & 15 deletions

File tree

libraries/gd.h

src/hooks.cpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,7 @@ void __fastcall Hooks::PlayLayer::update_H(gd::PlayLayer* self, int, float dt) {
110110
if (rs.get_frame_advance()) return;
111111
if (rs.is_playing()) rs.handle_playing();
112112
if (rs.recorder.m_recording) {
113-
if (!self->m_hasLevelCompleteMenu) {
114-
auto frame_dt = 1. / static_cast<double>(rs.recorder.m_fps);
115-
auto time = self->m_time + rs.recorder.m_extra_t - rs.recorder.m_last_frame_t;
116-
if (time >= frame_dt) {
117-
gd::FMODAudioEngine::sharedEngine()->setBackgroundMusicTime(self->m_time + from_offset<float>(self->m_levelSettings, 0xfc) + g_xpos_time);
118-
rs.recorder.m_extra_t = time - frame_dt;
119-
rs.recorder.m_last_frame_t = self->m_time;
120-
rs.recorder.capture_frame();
121-
}
122-
} else {
123-
rs.recorder.stop();
124-
}
113+
rs.recorder.handle_recording(self, dt);
125114
}
126115
update(self, dt);
127116
}
@@ -152,7 +141,8 @@ int __fastcall Hooks::PlayLayer::resetLevel_H(gd::PlayLayer* self, int) {
152141
rs.on_reset();
153142
// from what i've checked rob doesnt store this anywhere, so i have to calculate it again
154143
if (rs.recorder.m_recording)
155-
g_xpos_time = self->timeForXPos2(self->m_player1->m_position.x, self->m_isTestMode);
144+
rs.recorder.m_song_start_offset = self->timeForXPos2(
145+
self->m_player1->m_position.x, self->m_isTestMode) + self->m_levelSettings->m_songStartOffset;
156146
return ret;
157147
}
158148

src/recorder.cpp

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ Recorder::Recorder() : m_width(1280), m_height(720), m_fps(60) {}
66

77
void Recorder::start(const std::string& path) {
88
m_recording = true;
9+
m_finished_level = false;
910
m_last_frame_t = m_extra_t = 0;
11+
m_after_end_extra_time = 0.f;
1012
m_renderer.m_width = m_width;
1113
m_renderer.m_height = m_height;
1214
m_renderer.begin();
13-
std::thread([&, path]() {
15+
auto play_layer = gd::GameManager::sharedState()->getPlayLayer();
16+
auto song_file = play_layer->m_level->getAudioFileName();
17+
// these are always false???
18+
auto fade_in = play_layer->m_levelSettings->m_fadeIn;
19+
auto fade_out = play_layer->m_levelSettings->m_fadeOut;
20+
std::thread([&, path, song_file]() {
1421
std::stringstream stream;
1522
stream << "ffmpeg -y -f rawvideo -pix_fmt rgb24 -s " << m_width << "x" << m_height << " -r " << m_fps
1623
<< " -i - ";
@@ -23,6 +30,7 @@ void Recorder::start(const std::string& path) {
2330
else
2431
stream << "-pix_fmt yuv420p ";
2532
stream << "-vf \"vflip\" -an \"" << path << "\" "; // i hope just putting it in "" escapes it
33+
std::cout << "executing: " << stream.str() << std::endl;
2634
auto process = subprocess::Popen(stream.str());
2735
while (m_recording) {
2836
m_lock.lock();
@@ -35,6 +43,20 @@ void Recorder::start(const std::string& path) {
3543
}
3644
process.close();
3745
std::cout << "should be done now!" << std::endl;
46+
std::cout << "sike" << std::endl;
47+
auto total_time = m_last_frame_t; // 1 frame too short?
48+
{
49+
std::stringstream stream;
50+
stream << "ffmpeg -y -ss " << m_song_start_offset << " -i \"" << song_file
51+
<< "\" -i \"" << path << "\" -t " << total_time << " -c:v copy "
52+
<< "-filter:a \"";
53+
std::cout << "in " << fade_in << " out " << fade_out << std::endl;
54+
stream << "afade=t=in:d=0.5[out];[out]afade=t=out:d=0.5:st=" << (total_time - 0.5f - 3.f - 1.f);
55+
stream << "\" " << path << ".sound.mp4";
56+
std::cout << "executing: " << stream.str() << std::endl;
57+
auto process = subprocess::Popen(stream.str());
58+
process.close();
59+
}
3860
}).detach();
3961
}
4062

@@ -99,4 +121,24 @@ void Recorder::capture_frame() {
99121
m_lock.lock();
100122
m_frames.push(frame);
101123
m_lock.unlock();
124+
}
125+
126+
void Recorder::handle_recording(gd::PlayLayer* play_layer, float dt) {
127+
if (!play_layer->m_hasLevelCompleteMenu || m_after_end_extra_time < 3.f) {
128+
if (play_layer->m_hasLevelCompleteMenu) {
129+
m_after_end_extra_time += dt;
130+
m_finished_level = true;
131+
}
132+
auto frame_dt = 1. / static_cast<double>(m_fps);
133+
auto time = play_layer->m_time + m_extra_t - m_last_frame_t;
134+
if (time >= frame_dt) {
135+
gd::FMODAudioEngine::sharedEngine()->setBackgroundMusicTime(
136+
play_layer->m_time + m_song_start_offset);
137+
m_extra_t = time - frame_dt;
138+
m_last_frame_t = play_layer->m_time;
139+
capture_frame();
140+
}
141+
} else {
142+
stop();
143+
}
102144
}

src/recorder.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ class Recorder {
5858
double m_last_frame_t, m_extra_t;
5959
bool m_until_end = true;
6060
std::string m_codec = "", m_bitrate = "30M", m_extra_args = "";
61+
float m_after_end_extra_time;
62+
float m_song_start_offset;
63+
bool m_finished_level;
6164

6265
void start(const std::string& path);
6366
void stop();
6467
void capture_frame();
68+
void handle_recording(gd::PlayLayer*, float dt);
6569
};

0 commit comments

Comments
 (0)