--- liblscp/trunk/src/client.c 2004/06/24 18:25:11 144 +++ liblscp/trunk/src/client.c 2004/07/02 14:36:43 167 @@ -46,7 +46,7 @@ char *pszToken; char *pch; int cchToken; - lscp_event_t event = LSCP_EVENT_NONE; + lscp_event_t event; #ifdef DEBUG fprintf(stderr, "_lscp_client_evt_proc: Client waiting for events.\n"); @@ -62,18 +62,7 @@ pszToken = lscp_strtok(achBuffer, pszSeps, &(pch)); // Have "NOTIFY". if (strcasecmp(pszToken, "NOTIFY") == 0) { pszToken = lscp_strtok(NULL, pszSeps, &(pch)); - if (strcasecmp(pszToken, "CHANNELS") == 0) - event = LSCP_EVENT_CHANNELS; - else if (strcasecmp(pszToken, "VOICE_COUNT") == 0) - event = LSCP_EVENT_VOICE_COUNT; - else if (strcasecmp(pszToken, "STREAM_COUNT") == 0) - event = LSCP_EVENT_STREAM_COUNT; - else if (strcasecmp(pszToken, "BUFFER_FILL") == 0) - event = LSCP_EVENT_BUFFER_FILL; - else if (strcasecmp(pszToken, "CHANNEL_INFO") == 0) - event = LSCP_EVENT_CHANNEL_INFO; - else if (strcasecmp(pszToken, "MISCELLANEOUS") == 0) - event = LSCP_EVENT_MISCELLANEOUS; + event = lscp_event_from_text(pszToken); // And pick the rest of data... pszToken = lscp_strtok(NULL, pszSeps, &(pch)); cchToken = (pszToken == NULL ? 0 : strlen(pszToken)); @@ -153,7 +142,7 @@ // Subscribe to a single event. static lscp_status_t _lscp_client_evt_request ( lscp_client_t *pClient, int iSubscribe, lscp_event_t event ) { - char *pszEvent; + const char *pszEvent; char szQuery[LSCP_BUFSIZ]; int cchQuery; @@ -161,29 +150,10 @@ return LSCP_FAILED; // Which (single) event? - switch (event) { - case LSCP_EVENT_CHANNELS: - pszEvent = "CHANNELS"; - break; - case LSCP_EVENT_VOICE_COUNT: - pszEvent = "VOICE_COUNT"; - break; - case LSCP_EVENT_STREAM_COUNT: - pszEvent = "STREAM_COUNT"; - break; - case LSCP_EVENT_BUFFER_FILL: - pszEvent = "BUFFER_FILL"; - break; - case LSCP_EVENT_CHANNEL_INFO: - pszEvent = "CHANNEL_INFO"; - break; - case LSCP_EVENT_MISCELLANEOUS: - pszEvent = "CHANNEL_INFO"; - break; - default: + pszEvent = lscp_event_to_text(event); + if (pszEvent == NULL) return LSCP_FAILED; - } - + // Build the query string... cchQuery = sprintf(szQuery, "%sSUBSCRIBE %s\n\n", (iSubscribe == 0 ? "UN" : ""), pszEvent); // Just send data, forget result... @@ -322,6 +292,8 @@ pClient->channels = NULL; lscp_driver_info_init(&(pClient->audio_info)); lscp_driver_info_init(&(pClient->midi_info)); + lscp_param_info_init(&(pClient->audio_param_info)); + lscp_param_info_init(&(pClient->midi_param_info)); lscp_engine_info_init(&(pClient->engine_info)); lscp_channel_info_init(&(pClient->channel_info)); // Initialize error stuff. @@ -384,6 +356,8 @@ // Free up all cached members. lscp_channel_info_reset(&(pClient->channel_info)); lscp_engine_info_reset(&(pClient->engine_info)); + lscp_param_info_reset(&(pClient->midi_param_info)); + lscp_param_info_reset(&(pClient->audio_param_info)); lscp_driver_info_reset(&(pClient->midi_info)); lscp_driver_info_reset(&(pClient->audio_info)); // Free available engine table. @@ -399,7 +373,7 @@ pClient->engines = NULL; // Free result error stuff. lscp_client_set_result(pClient, NULL, 0); - // Frre stream usage stuff. + // Free stream usage stuff. if (pClient->buffer_fill) free(pClient->buffer_fill); pClient->buffer_fill = NULL; @@ -1017,6 +991,9 @@ * Current number of active disk streams: * GET CHANNEL STREAM_COUNT * + * @param pClient Pointer to client instance structure. + * @param iSamplerChannel Sampler channel number. + * * @returns The number of active disk streams on success, -1 otherwise. */ int lscp_get_channel_stream_count ( lscp_client_t *pClient, int iSamplerChannel ) @@ -1041,6 +1018,60 @@ } +/** + * Current least usage of active disk streams. + * + * @param pClient Pointer to client instance structure. + * @param iSamplerChannel Sampler channel number. + * + * @returns The usage percentage of the least filled active disk stream + * on success, -1 otherwise. + */ +int lscp_get_channel_stream_usage ( lscp_client_t *pClient, int iSamplerChannel ) +{ + char szQuery[LSCP_BUFSIZ]; + int iStreamUsage = -1; + const char *pszResult; + const char *pszSeps = "[]%,"; + char *pszToken; + char *pch; + int iStream; + int iPercent; + + if (iSamplerChannel < 0) + return iStreamUsage; + + // Lock this section up. + lscp_mutex_lock(pClient->mutex); + + iStream = 0; + sprintf(szQuery, "GET CHANNEL BUFFER_FILL PERCENTAGE %d\r\n", iSamplerChannel); + if (lscp_client_call(pClient, szQuery) == LSCP_OK) { + pszResult = lscp_client_get_result(pClient); + pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); + while (pszToken) { + if (*pszToken) { + // Skip stream id. + pszToken = lscp_strtok(NULL, pszSeps, &(pch)); + if (pszToken == NULL) + break; + // Get least buffer fill percentage. + iPercent = atol(pszToken); + if (iStreamUsage > iPercent || iStream == 0) + iStreamUsage = iPercent; + iStream++; + } + pszToken = lscp_strtok(NULL, pszSeps, &(pch)); + } + } + + // Unlock this section down. + lscp_mutex_unlock(pClient->mutex); + + return iStreamUsage; +} + + /** * Current fill state of disk stream buffers: * GET CHANNEL BUFFER_FILL {BYTES|PERCENTAGE}