4
4
#include < vector>
5
5
#include " device/spu/spu.h"
6
6
#include " system.h"
7
+ #include " sound/wave.h"
7
8
#include < SDL.h>
9
+ #include < utils/event.h>
10
+ #include < iomanip>
11
+ #include < config.h>
12
+ #include < sstream>
13
+ #include " platform/windows/gui/helper/file_dialog.h"
8
14
9
15
namespace ImGui {
10
16
template <typename ... Args>
@@ -297,6 +303,38 @@ void renderSamples(spu::SPU* spu) {
297
303
ImGui::PlotLines (" Preview" , samples.data (), (int )samples.size (), 0 , nullptr , -1 .0f , 1 .0f , ImVec2 (400 , 80 ));
298
304
}
299
305
306
+ void SPU::recordingWindow (spu::SPU* spu) {
307
+ if (ImGui::Button (spu->recording ? " Pause" : " Record" )) {
308
+ spu->recording = !spu->recording ;
309
+ }
310
+ if (!spu->recordBuffer .empty ()) {
311
+ if (!spu->recording ) {
312
+ ImGui::SameLine ();
313
+ if (ImGui::Button (" Save" )) {
314
+ auto t = std::time (nullptr );
315
+ std::stringstream ss;
316
+ ss << std::put_time (std::localtime (&t), " spu-%Y-%m-%d_%H-%M-%S.wav" );
317
+ auto file = ss.str ();
318
+
319
+ bool saved = wave::writeToFile (spu->recordBuffer , fmt::format (" {}/{}" , avocado::PATH_USER, file).c_str ());
320
+ toast (saved ? fmt::format (" Saved to {}" , file) : fmt::format (" Problem saving to {}" , file));
321
+ if (saved) {
322
+ spu->recordBuffer .clear ();
323
+ showOpenDirectory = true ;
324
+ }
325
+ }
326
+ }
327
+
328
+ ImGui::SameLine ();
329
+ ImGui::TextUnformatted (fmt::format (" {:.2f} seconds captured..." , spu->recordBuffer .size () / 44100 .f / 2 ).c_str ());
330
+ }
331
+
332
+ if (showOpenDirectory) {
333
+ ImGui::SameLine ();
334
+ gui::helper::openFileBrowserButton (avocado::PATH_USER);
335
+ }
336
+ }
337
+
300
338
void SPU::spuWindow (spu::SPU* spu) {
301
339
const auto treeFlags = ImGuiTreeNodeFlags_CollapsingHeader | ImGuiTreeNodeFlags_DefaultOpen;
302
340
static bool parseValues = true ;
@@ -309,6 +347,8 @@ void SPU::spuWindow(spu::SPU* spu) {
309
347
310
348
ImGui::Checkbox (" Parse values" , &parseValues);
311
349
renderSamples (spu);
350
+
351
+ if (ImGui::TreeNodeEx (" Recording" , treeFlags)) recordingWindow (spu);
312
352
ImGui::End ();
313
353
}
314
354
0 commit comments