demo mode change state at random each 4 beats
This commit is contained in:
+10
-2
@@ -270,7 +270,7 @@ void state_apply_event(SharedContext *context, StateConfig state_config,
|
|||||||
bool state_background_midi_write(SharedContext *context,
|
bool state_background_midi_write(SharedContext *context,
|
||||||
StateConfig state_config, MidiDevice midi) {
|
StateConfig state_config, MidiDevice midi) {
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
bool beat_active, last_active;
|
bool beat_active, last_active, change, last_change;
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
@@ -289,7 +289,7 @@ bool state_background_midi_write(SharedContext *context,
|
|||||||
last_active = false;
|
last_active = false;
|
||||||
|
|
||||||
while (!context->stop) {
|
while (!context->stop) {
|
||||||
beat_active = tempo_progress(context->tempo) < 0.25;
|
beat_active = tempo_progress(context->tempo, 1.0) < 0.25;
|
||||||
|
|
||||||
if (beat_active != last_active) {
|
if (beat_active != last_active) {
|
||||||
safe_midi_write(midi, state_config.tap_tempo_code,
|
safe_midi_write(midi, state_config.tap_tempo_code,
|
||||||
@@ -301,6 +301,14 @@ bool state_background_midi_write(SharedContext *context,
|
|||||||
|
|
||||||
last_active = beat_active;
|
last_active = beat_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
change = tempo_progress(context->tempo, 4.0) < 0.25;
|
||||||
|
|
||||||
|
if (change && !last_change && context->demo) {
|
||||||
|
state_randomize(context, state_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
last_change = change;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_info("(state) background writing stopped by main thread (pid: %d)", pid);
|
log_info("(state) background writing stopped by main thread (pid: %d)", pid);
|
||||||
|
|||||||
+3
-2
@@ -113,10 +113,11 @@ void tempo_tap(Tempo *tempo) {
|
|||||||
add_tap_to_chain(tempo, t);
|
add_tap_to_chain(tempo, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
double tempo_progress(Tempo tempo) {
|
double tempo_progress(Tempo tempo, double modulo) {
|
||||||
long t;
|
long t;
|
||||||
|
|
||||||
t = now();
|
t = now();
|
||||||
|
|
||||||
return fmod((double)(t - tempo.last_reset) / (double)tempo.beat_length, 1.0);
|
return fmod((double)(t - tempo.last_reset) / (double)tempo.beat_length,
|
||||||
|
modulo);
|
||||||
}
|
}
|
||||||
+1
-1
@@ -9,6 +9,6 @@ void tempo_tap(Tempo *tempo);
|
|||||||
|
|
||||||
void tempo_set(Tempo *tempo, float value);
|
void tempo_set(Tempo *tempo, float value);
|
||||||
|
|
||||||
double tempo_progress(Tempo tempo);
|
double tempo_progress(Tempo tempo, double modulo);
|
||||||
|
|
||||||
#endif /* TEMPO_H */
|
#endif /* TEMPO_H */
|
||||||
Reference in New Issue
Block a user