Skip to content

Commit 2b64cde

Browse files
committed
default to record once with priming
1 parent a2107c4 commit 2b64cde

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

clients/oooooooo/src/KeyboardHandler.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,21 @@ void KeyboardHandler::handleKeyDown(SDL_Keycode key, bool isRepeat,
4848
break;
4949
case SDLK_p:
5050
if (!isRepeat) {
51-
if (softcut_->WasPrimed(*selectedLoop) &&
52-
softcut_->IsRecording(*selectedLoop)) {
53-
softcut_->ToggleRecord(*selectedLoop);
51+
if (keysHeld_[SDLK_LCTRL] || keysHeld_[SDLK_RCTRL]) {
52+
// pause and set to 0
53+
softcut_->TogglePlay(*selectedLoop, false);
54+
float startTimeDest = softcut_->getLoopStart(*selectedLoop);
55+
// cut to the start
56+
softcut_->handleCommand(new Commands::CommandPacket(
57+
Commands::Id::SET_CUT_POSITION, *selectedLoop, startTimeDest));
58+
5459
} else {
55-
softcut_->TogglePlay(*selectedLoop);
60+
if (softcut_->WasPrimed(*selectedLoop) &&
61+
softcut_->IsRecording(*selectedLoop)) {
62+
softcut_->ToggleRecord(*selectedLoop);
63+
} else {
64+
softcut_->TogglePlay(*selectedLoop);
65+
}
5666
}
5767
}
5868
break;
@@ -103,7 +113,7 @@ void KeyboardHandler::handleKeyDown(SDL_Keycode key, bool isRepeat,
103113
}
104114

105115
} else if (keysHeld_[SDLK_LSHIFT] || keysHeld_[SDLK_RSHIFT]) {
106-
softcut_->ToggleRecordOnce(*selectedLoop);
116+
softcut_->TogglePrimeToRecordOnce(*selectedLoop);
107117
} else {
108118
softcut_->ToggleRecord(*selectedLoop);
109119
}

clients/oooooooo/src/SoftcutClient.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,18 @@ void SoftcutClient::process(jack_nframes_t numFrames) {
124124
rms += input[v].buf[0][i] * input[v].buf[0][i];
125125
}
126126
rms = sqrt(rms / static_cast<float>(numFrames));
127+
if (isPrimed[v]) {
128+
std::cerr << "primed: " << v << " rms: " << amp2db(rms)
129+
<< " sensitivity: " << primeSensitivity[v] << std::endl;
130+
}
127131
if (amp2db(rms) > primeSensitivity[v] && isPrimed[v]) {
128-
ToggleRecord(v, true);
132+
if (isPrimedToRecordOnce[v]) {
133+
ToggleRecordOnce(v);
134+
isPrimedToRecordOnce[v] = false;
135+
isPrimed[v] = false;
136+
} else {
137+
ToggleRecord(v, true);
138+
}
129139
}
130140
blockRMS[v] = rms;
131141
}

clients/oooooooo/src/SoftcutClient.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ class SoftcutClient : public JackClient<2, 2> {
7979
doneRecordingPrimed[i] = false;
8080
isPrimed[i] = !isPrimed[i];
8181
}
82+
void TogglePrimeToRecordOnce(int i) {
83+
wasPrimed[i] = false;
84+
doneRecordingPrimed[i] = false;
85+
isPrimed[i] = !isPrimed[i];
86+
isPrimedToRecordOnce[i] = isPrimed[i];
87+
}
8288
bool IsPrimed(int i) { return isPrimed[i]; }
89+
bool IsPrimedToRecordOnce(int i) {
90+
return isPrimed[i] && isPrimedToRecordOnce[i];
91+
}
8392
bool WasPrimed(int i) { return wasPrimed[i]; }
8493
void SetWasPrimed(int i, bool was) { wasPrimed[i] = was; }
8594
bool IsDoneRecordingPrimed(int i) {
@@ -102,6 +111,7 @@ class SoftcutClient : public JackClient<2, 2> {
102111
void TogglePlay(int i) {
103112
cut.setPlayFlag(i, !IsPlaying(i));
104113
isPrimed[i] = false;
114+
isPrimedToRecordOnce[i] = false;
105115
wasPrimed[i] = false;
106116
doneRecordingPrimed[i] = false;
107117
}
@@ -114,9 +124,11 @@ class SoftcutClient : public JackClient<2, 2> {
114124
}
115125
float getCPUUsage() { return static_cast<float>(jack_cpu_load(client)); }
116126
void SetPrimeSensitivity(int i, float sensitivity) {
117-
if (i >= 0 && i < NumVoices) {
118-
primeSensitivity[i] = sensitivity;
127+
for (int j = 0; j < NumVoices; ++j) {
128+
primeSensitivity[j] = sensitivity;
119129
}
130+
std::cerr << "SetPrimeSensitivity: " << i << " to " << primeSensitivity[i]
131+
<< std::endl;
120132
}
121133

122134
private:
@@ -143,6 +155,7 @@ class SoftcutClient : public JackClient<2, 2> {
143155
VUMeter vuMeters[NumVoices];
144156
sample_t blockRMS[NumVoices];
145157
bool isPrimed[NumVoices];
158+
bool isPrimedToRecordOnce[NumVoices];
146159
bool wasPrimed[NumVoices];
147160
bool doneRecordingPrimed[NumVoices];
148161
float primeSensitivity[NumVoices];

0 commit comments

Comments
 (0)