1+
12#include " KeyboardHandler.h"
23
4+ #include < chrono>
5+ #include < ctime>
6+ #include < filesystem>
7+ #include < fstream>
8+ #include < iomanip>
9+ #include < iostream>
10+
11+ #include " Display.h"
312#include " Parameters.h"
413#include " SoftcutClient.h"
514
615using namespace softcut_jack_osc ;
716
817void KeyboardHandler::handleKeyDown (SDL_Keycode key, bool isRepeat,
9- SDL_Keymod modifiers, int *selectedLoop) {
18+ SDL_Keymod modifiers [[maybe_unused]],
19+ int *selectedLoop) {
1020 keysHeld_[key] = true ;
1121
1222 // std::cerr << "KeyboardHandler::handleKeyDown Key pressed: "
@@ -125,10 +135,33 @@ void KeyboardHandler::handleKeyDown(SDL_Keycode key, bool isRepeat,
125135 std::string path = " oooooooo/loop_" + std::to_string (i) + " .wav" ;
126136 softcut_->loadBufferToLoop (path, i);
127137 }
138+
139+ std::filesystem::path filePath (" oooooooo/loop_0.wav" );
140+ if (std::filesystem::exists (filePath)) {
141+ auto ftime = std::filesystem::last_write_time (filePath);
142+ // Convert file_time_type to system_clock::time_point
143+ auto sctp = std::chrono::time_point_cast<
144+ std::chrono::system_clock::duration>(
145+ ftime - decltype (ftime)::clock::now () +
146+ std::chrono::system_clock::now ());
147+ // Convert to time_t
148+ std::time_t cftime = std::chrono::system_clock::to_time_t (sctp);
149+ // Format time
150+ char timeStr[100 ];
151+ std::strftime (timeStr, sizeof (timeStr), " %Y-%m-%d %H:%M:%S" ,
152+ std::localtime (&cftime));
153+
154+ display_->SetMessage (
155+ " Audio loaded from "
156+ " modified: " +
157+ std::string (timeStr),
158+ 3 );
159+ }
128160 } else {
129161 // load the parameters
130162 JSON json;
131163 std::ifstream file (" oooooooo/parameters.json" );
164+ // get the last-modified date from the file
132165 if (file.is_open ()) {
133166 file >> json;
134167 file.close ();
@@ -140,6 +173,26 @@ void KeyboardHandler::handleKeyDown(SDL_Keycode key, bool isRepeat,
140173 for (int i = 0 ; i < numVoices_; i++) {
141174 params_[i].Bang ();
142175 }
176+
177+ std::filesystem::path filePath (" oooooooo/parameters.json" );
178+ auto ftime = std::filesystem::last_write_time (filePath);
179+ // Convert file_time_type to system_clock::time_point
180+ auto sctp = std::chrono::time_point_cast<
181+ std::chrono::system_clock::duration>(
182+ ftime - decltype (ftime)::clock::now () +
183+ std::chrono::system_clock::now ());
184+ // Convert to time_t
185+ std::time_t cftime = std::chrono::system_clock::to_time_t (sctp);
186+ // Format time
187+ char timeStr[100 ];
188+ std::strftime (timeStr, sizeof (timeStr), " %Y-%m-%d %H:%M:%S" ,
189+ std::localtime (&cftime));
190+
191+ display_->SetMessage (
192+ " Parameters loaded from "
193+ " modified: " +
194+ std::string (timeStr),
195+ 3 );
143196 } else {
144197 std::cerr << " Error opening file for reading" << std::endl;
145198 }
@@ -220,7 +273,8 @@ void KeyboardHandler::handleKeyDown(SDL_Keycode key, bool isRepeat,
220273 }
221274}
222275
223- void KeyboardHandler::handleKeyUp (SDL_Keycode key, int selectedLoop) {
276+ void KeyboardHandler::handleKeyUp (SDL_Keycode key,
277+ int selectedLoop [[maybe_unused]]) {
224278 keysHeld_[key] = false ;
225279 // std::cerr << "KeyboardHandler::handleKeyUp Key released: "
226280 // << SDL_GetKeyName(key) << " " << selectedLoop << std::endl;
0 commit comments