Skip to content

Commit 3cea134

Browse files
committed
add messaging for loading
1 parent 16e3f0d commit 3cea134

File tree

5 files changed

+65
-13
lines changed

5 files changed

+65
-13
lines changed

clients/oooooooo/src/Display.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ void Display::init(SoftcutClient* sc, int numVoices) {
581581
}
582582

583583
// setup keyboard handler
584-
keyboardHandler_.Init(softCutClient_, params_, numVoices_);
584+
keyboardHandler_.Init(softCutClient_, params_, numVoices_, this);
585585

586586
// setup help system
587587
helpSystem_.Init(font);

clients/oooooooo/src/DisplayMessage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ void DisplayMessage::Render(SDL_Renderer* renderer, int windowWidth,
9191
}
9292
// Position the message in the bottom-right corner with some padding
9393
int padding = 10;
94-
int x = windowWidth - surface->w - padding;
94+
int x = padding;
9595
int y = windowHeight - surface->h - padding;
9696

9797
SDL_Rect destRect = {x, y, surface->w, surface->h};

clients/oooooooo/src/KeyboardHandler.cpp

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
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

615
using namespace softcut_jack_osc;
716

817
void 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;

clients/oooooooo/src/KeyboardHandler.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111
#include "Parameters.h"
1212
#include "SoftcutClient.h"
1313

14+
class Display;
15+
1416
class KeyboardHandler {
1517
public:
1618
KeyboardHandler() = default;
1719
~KeyboardHandler() = default;
1820

19-
void Init(SoftcutClient* sc, Parameters* params, int numVoices) {
21+
void Init(SoftcutClient* sc, Parameters* params, int numVoices,
22+
Display* display) {
2023
softcut_ = sc;
2124
params_ = params;
2225
numVoices_ = numVoices;
26+
display_ = display;
2327
}
2428

2529
void handleKeyDown(SDL_Keycode key, bool isRepeat, SDL_Keymod modifiers,
@@ -31,6 +35,7 @@ class KeyboardHandler {
3135
Parameters* params_;
3236
int numVoices_;
3337
int voiceToCopy_ = -1;
38+
Display* display_;
3439

3540
std::unordered_map<SDL_Keycode, bool> keysHeld_;
3641
};

clients/oooooooo/src/Parameters.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,27 +156,20 @@ void Parameters::Init(SoftcutClient* sc, int voice, float sample_rate) {
156156
sample_rate_, 0.0, softCutClient_->getLoopEnd(voice), 0.01f,
157157
default_value, 0.0f, 0.2f, 0.1f, random_lfo, "start", "s",
158158
[this, voice](float value) {
159-
std::cerr << "start: " << value << std::endl;
160-
float loop_duration = softCutClient_->getDuration(voice);
161159
softCutClient_->handleCommand(new Commands::CommandPacket(
162160
Commands::Id::SET_CUT_LOOP_START, voice,
163161
value + softCutClient_->getLoopMin(voice)));
164-
softCutClient_->handleCommand(new Commands::CommandPacket(
165-
Commands::Id::SET_CUT_LOOP_END, voice,
166-
value + softCutClient_->getLoopMin(voice) + loop_duration));
167162
});
168163
break;
169164
case PARAM_DURATION:
170165
default_value = 2.0f;
171166
param_[i].Init(
172-
sample_rate_, 0.0, 60.0f, 0.01f, default_value,
167+
sample_rate_, 0.0, 600.0f, 0.01f, default_value,
173168
default_value - 1.0f, default_value + 1.0f, 0.1f, random_lfo,
174169
"duration", "s", [this, voice](float value) {
175-
std::cerr << "duration: " << value << std::endl;
176170
float start = softCutClient_->getLoopStart(voice);
177171
softCutClient_->handleCommand(new Commands::CommandPacket(
178172
Commands::Id::SET_CUT_LOOP_END, voice, value + start));
179-
param_[PARAM_START].SetMax(value);
180173
});
181174
break;
182175
case PARAM_REC_LEVEL:

0 commit comments

Comments
 (0)