Skip to content

Commit b6ecd76

Browse files
committed
Cache and ignore repeated port-state-update requests
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 361a2a4 commit b6ecd76

File tree

1 file changed

+34
-12
lines changed

1 file changed

+34
-12
lines changed

src/effects.c

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,15 +1247,16 @@ static bool ShouldIgnorePostPonedEffectEvent(int effect_id, postponed_cached_eff
12471247
return false;
12481248
}
12491249

1250-
static bool ShouldIgnorePostPonedSymbolEvent(postponed_parameter_event_t* ev,
1250+
static bool ShouldIgnorePostPonedSymbolEvent(int effect_id,
1251+
const char* symbol,
12511252
postponed_cached_symbol_events* cached_events)
12521253
{
12531254
// symbol must not be null
1254-
if (ev->symbol == NULL)
1255+
if (symbol == NULL)
12551256
return false;
12561257

1257-
if (ev->effect_id == cached_events->last_effect_id &&
1258-
strncmp(ev->symbol, cached_events->last_symbol, MAX_CHAR_BUF_SIZE) == 0)
1258+
if (effect_id == cached_events->last_effect_id &&
1259+
strncmp(symbol, cached_events->last_symbol, MAX_CHAR_BUF_SIZE) == 0)
12591260
{
12601261
// already received this event, like just now
12611262
return true;
@@ -1268,8 +1269,8 @@ static bool ShouldIgnorePostPonedSymbolEvent(postponed_parameter_event_t* ev,
12681269
{
12691270
postponed_cached_symbol_list_data* const psymbol = list_entry(it, postponed_cached_symbol_list_data, siblings);
12701271

1271-
if (ev->effect_id == psymbol->effect_id &&
1272-
strncmp(ev->symbol, psymbol->symbol, MAX_CHAR_BUF_SIZE) == 0)
1272+
if (effect_id == psymbol->effect_id &&
1273+
strncmp(symbol, psymbol->symbol, MAX_CHAR_BUF_SIZE) == 0)
12731274
{
12741275
// haha! found you little bastard!
12751276
return true;
@@ -1282,8 +1283,8 @@ static bool ShouldIgnorePostPonedSymbolEvent(postponed_parameter_event_t* ev,
12821283

12831284
if (psymbol)
12841285
{
1285-
psymbol->effect_id = ev->effect_id;
1286-
strncpy(psymbol->symbol, ev->symbol, MAX_CHAR_BUF_SIZE);
1286+
psymbol->effect_id = effect_id;
1287+
strncpy(psymbol->symbol, symbol, MAX_CHAR_BUF_SIZE);
12871288
psymbol->symbol[MAX_CHAR_BUF_SIZE] = '\0';
12881289
list_add_tail(&psymbol->siblings, &cached_events->symbols.siblings);
12891290
}
@@ -1342,19 +1343,23 @@ static void RunPostPonedEvents(int ignored_effect_id)
13421343
bool got_midi_program = false;
13431344
bool got_transport = false;
13441345
postponed_cached_effect_events cached_audio_monitor, cached_process_out_buf;
1345-
postponed_cached_symbol_events cached_param_set, cached_output_mon;
1346+
postponed_cached_symbol_events cached_param_set, cached_param_state, cached_output_mon;
13461347

13471348
cached_audio_monitor.last_effect_id = -1;
13481349
cached_process_out_buf.last_effect_id = -1;
13491350
cached_param_set.last_effect_id = -1;
13501351
cached_param_set.last_symbol[0] = '\0';
13511352
cached_param_set.last_symbol[MAX_CHAR_BUF_SIZE] = '\0';
1353+
cached_param_state.last_effect_id = -1;
1354+
cached_param_state.last_symbol[0] = '\0';
1355+
cached_param_state.last_symbol[MAX_CHAR_BUF_SIZE] = '\0';
13521356
cached_output_mon.last_effect_id = -1;
13531357
cached_output_mon.last_symbol[0] = '\0';
13541358
cached_output_mon.last_symbol[MAX_CHAR_BUF_SIZE] = '\0';
13551359
INIT_LIST_HEAD(&cached_audio_monitor.effects.siblings);
13561360
INIT_LIST_HEAD(&cached_process_out_buf.effects.siblings);
13571361
INIT_LIST_HEAD(&cached_param_set.symbols.siblings);
1362+
INIT_LIST_HEAD(&cached_param_state.symbols.siblings);
13581363
INIT_LIST_HEAD(&cached_output_mon.symbols.siblings);
13591364

13601365
// if all we have are jack_midi_connect requests, do not send feedback to server
@@ -1388,7 +1393,9 @@ static void RunPostPonedEvents(int ignored_effect_id)
13881393
case POSTPONED_PARAM_SET:
13891394
if (eventptr->event.parameter.effect_id == ignored_effect_id)
13901395
continue;
1391-
if (ShouldIgnorePostPonedSymbolEvent(&eventptr->event.parameter, &cached_param_set))
1396+
if (ShouldIgnorePostPonedSymbolEvent(eventptr->event.parameter.effect_id,
1397+
eventptr->event.parameter.symbol,
1398+
&cached_param_set))
13921399
continue;
13931400

13941401
snprintf(buf, FEEDBACK_BUF_SIZE, "param_set %i %s %f", eventptr->event.parameter.effect_id,
@@ -1402,13 +1409,21 @@ static void RunPostPonedEvents(int ignored_effect_id)
14021409
break;
14031410

14041411
case POSTPONED_PARAM_STATE:
1405-
if (eventptr->event.parameter.effect_id == ignored_effect_id)
1412+
if (eventptr->event.state.effect_id == ignored_effect_id)
1413+
continue;
1414+
if (ShouldIgnorePostPonedSymbolEvent(eventptr->event.state.effect_id,
1415+
eventptr->event.state.symbol,
1416+
&cached_param_state))
14061417
continue;
14071418

14081419
snprintf(buf, FEEDBACK_BUF_SIZE, "param_state %i %s %i", eventptr->event.state.effect_id,
14091420
eventptr->event.state.symbol,
14101421
eventptr->event.state.state);
14111422
socket_send_feedback_debug(buf);
1423+
1424+
// save for fast checkup next time
1425+
cached_param_state.last_effect_id = eventptr->event.state.effect_id;
1426+
strncpy(cached_param_state.last_symbol, eventptr->event.state.symbol, MAX_CHAR_BUF_SIZE);
14121427
break;
14131428

14141429
case POSTPONED_AUDIO_MONITOR:
@@ -1431,7 +1446,9 @@ static void RunPostPonedEvents(int ignored_effect_id)
14311446
case POSTPONED_OUTPUT_MONITOR:
14321447
if (eventptr->event.parameter.effect_id == ignored_effect_id)
14331448
continue;
1434-
if (ShouldIgnorePostPonedSymbolEvent(&eventptr->event.parameter, &cached_output_mon))
1449+
if (ShouldIgnorePostPonedSymbolEvent(eventptr->event.parameter.effect_id,
1450+
eventptr->event.parameter.symbol,
1451+
&cached_output_mon))
14351452
continue;
14361453

14371454
snprintf(buf, FEEDBACK_BUF_SIZE, "output_set %i %s %f", eventptr->event.parameter.effect_id,
@@ -1732,6 +1749,11 @@ static void RunPostPonedEvents(int ignored_effect_id)
17321749
psymbol = list_entry(it, postponed_cached_symbol_list_data, siblings);
17331750
free(psymbol);
17341751
}
1752+
list_for_each_safe(it, it2, &cached_param_state.symbols.siblings)
1753+
{
1754+
psymbol = list_entry(it, postponed_cached_symbol_list_data, siblings);
1755+
free(psymbol);
1756+
}
17351757
list_for_each_safe(it, it2, &cached_output_mon.symbols.siblings)
17361758
{
17371759
psymbol = list_entry(it, postponed_cached_symbol_list_data, siblings);

0 commit comments

Comments
 (0)