From e906fd2f63655d4a3795e62db3b60f0186e8dd45 Mon Sep 17 00:00:00 2001 From: jcorporation Date: Tue, 5 Jun 2018 23:04:45 +0100 Subject: [PATCH] Accept "nan" for mixrampdelay, sets it to -1 (disblaed) Issue #9 Changes types from double to float for mixrampdb and mixrampdelay --- htdocs/js/mpd.js | 7 ++++--- src/mpd_client.c | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/htdocs/js/mpd.js b/htdocs/js/mpd.js index 001913a..bae5073 100644 --- a/htdocs/js/mpd.js +++ b/htdocs/js/mpd.js @@ -976,7 +976,7 @@ function confirmSettings() { } } if (!$('#inputMixrampdb').is(':disabled')) { - value=parseFloat($('#inputMixrampdb').val()); + var value=parseFloat($('#inputMixrampdb').val()); if (!isNaN(value)) { $('#inputMixrampdb').val(value); } else { @@ -987,11 +987,12 @@ function confirmSettings() { } } if (!$('#inputMixrampdelay').is(':disabled')) { - value=parseFloat($('#inputMixrampdelay').val()); + if ($('#inputMixrampdelay').val() == 'nan') $('#inputMixrampdelay').val('-1'); + var value=parseFloat($('#inputMixrampdelay').val()); if (!isNaN(value)) { $('#inputMixrampdelay').val(value); } else { - $('#inputMixrampdelay').popover({"content":"Must be a number","trigger":"manual"}); + $('#inputMixrampdelay').popover({"content":"Must be a number, -1 to disable","trigger":"manual"}); $('#inputMixrampdelay').popover('show'); $('#inputMixrampdelay').focus(); formOK=false; diff --git a/src/mpd_client.c b/src/mpd_client.c index e6fb97e..b414af2 100644 --- a/src/mpd_client.c +++ b/src/mpd_client.c @@ -64,8 +64,8 @@ int callback_mpd(struct mg_connection *c) enum mpd_cmd_ids cmd_id = get_cmd_id(c->content); size_t n = 0; unsigned int uint_buf, uint_buf_2; - double double_buf; int int_buf; + float float_buf; char *p_charbuf = NULL, *token; char *p_charbuf2 = NULL; char *searchstr = NULL; @@ -139,12 +139,12 @@ int callback_mpd(struct mg_connection *c) mpd_run_crossfade(mpd.conn, uint_buf); break; case MPD_API_SET_MIXRAMPDB: - if(sscanf(c->content, "MPD_API_SET_MIXRAMPDB,%lf", &double_buf)) - mpd_run_mixrampdb(mpd.conn, double_buf); + if(sscanf(c->content, "MPD_API_SET_MIXRAMPDB,%f", &float_buf)) + mpd_run_mixrampdb(mpd.conn, float_buf); break; case MPD_API_SET_MIXRAMPDELAY: - if(sscanf(c->content, "MPD_API_SET_MIXRAMPDELAY,%lf", &double_buf)) - mpd_run_mixrampdelay(mpd.conn, double_buf); + if(sscanf(c->content, "MPD_API_SET_MIXRAMPDELAY,%f", &float_buf)) + mpd_run_mixrampdelay(mpd.conn, float_buf); break; case MPD_API_GET_OUTPUTS: mpd.buf_size = mpd_put_outputs(mpd.buf, 1); @@ -750,7 +750,7 @@ int mympd_put_settings(char *buffer) len = snprintf(buffer, MAX_SIZE, "{\"type\":\"settings\", \"data\":{" "\"repeat\":%d, \"single\":%d, \"crossfade\":%d, \"consume\":%d, \"random\":%d, " - "\"mixrampdb\": %lf, \"mixrampdelay\": %lf, \"mpdhost\" : \"%s\", \"mpdport\": \"%d\", \"passwort_set\": %s, " + "\"mixrampdb\": %f, \"mixrampdelay\": %f, \"mpdhost\" : \"%s\", \"mpdport\": \"%d\", \"passwort_set\": %s, " "\"streamport\": \"%d\",\"coverimage\": \"%s\", \"max_elements_per_page\": %d, \"replaygain\": \"%s\"" "}}", mpd_status_get_repeat(status),