2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
liblscp - LinuxSampler Control Protocol API |
liblscp - LinuxSampler Control Protocol API |
5 |
Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
|
7 |
This library is free software; you can redistribute it and/or |
This library is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU Lesser General Public |
modify it under the terms of the GNU Lesser General Public |
327 |
pClient->midi_devices = NULL; |
pClient->midi_devices = NULL; |
328 |
pClient->engines = NULL; |
pClient->engines = NULL; |
329 |
pClient->channels = NULL; |
pClient->channels = NULL; |
330 |
|
pClient->fxsends = NULL; |
331 |
pClient->midi_instruments = NULL; |
pClient->midi_instruments = NULL; |
332 |
pClient->midi_maps = NULL; |
pClient->midi_maps = NULL; |
333 |
pClient->midi_map_name = NULL; |
pClient->midi_map_name = NULL; |
344 |
lscp_server_info_init(&(pClient->server_info)); |
lscp_server_info_init(&(pClient->server_info)); |
345 |
lscp_engine_info_init(&(pClient->engine_info)); |
lscp_engine_info_init(&(pClient->engine_info)); |
346 |
lscp_channel_info_init(&(pClient->channel_info)); |
lscp_channel_info_init(&(pClient->channel_info)); |
347 |
|
lscp_fxsend_info_init(&(pClient->fxsend_info)); |
348 |
lscp_midi_instrument_info_init(&(pClient->midi_instrument_info)); |
lscp_midi_instrument_info_init(&(pClient->midi_instrument_info)); |
349 |
// Initialize error stuff. |
// Initialize error stuff. |
350 |
pClient->pszResult = NULL; |
pClient->pszResult = NULL; |
407 |
|
|
408 |
// Free up all cached members. |
// Free up all cached members. |
409 |
lscp_midi_instrument_info_free(&(pClient->midi_instrument_info)); |
lscp_midi_instrument_info_free(&(pClient->midi_instrument_info)); |
410 |
|
lscp_fxsend_info_free(&(pClient->fxsend_info)); |
411 |
lscp_channel_info_free(&(pClient->channel_info)); |
lscp_channel_info_free(&(pClient->channel_info)); |
412 |
lscp_engine_info_free(&(pClient->engine_info)); |
lscp_engine_info_free(&(pClient->engine_info)); |
413 |
lscp_server_info_free(&(pClient->server_info)); |
lscp_server_info_free(&(pClient->server_info)); |
428 |
lscp_isplit_destroy(pClient->midi_devices); |
lscp_isplit_destroy(pClient->midi_devices); |
429 |
lscp_szsplit_destroy(pClient->engines); |
lscp_szsplit_destroy(pClient->engines); |
430 |
lscp_isplit_destroy(pClient->channels); |
lscp_isplit_destroy(pClient->channels); |
431 |
|
lscp_isplit_destroy(pClient->fxsends); |
432 |
lscp_midi_instruments_destroy(pClient->midi_instruments); |
lscp_midi_instruments_destroy(pClient->midi_instruments); |
433 |
lscp_isplit_destroy(pClient->midi_maps); |
lscp_isplit_destroy(pClient->midi_maps); |
434 |
if (pClient->midi_map_name) |
if (pClient->midi_map_name) |
440 |
pClient->midi_devices = NULL; |
pClient->midi_devices = NULL; |
441 |
pClient->engines = NULL; |
pClient->engines = NULL; |
442 |
pClient->channels = NULL; |
pClient->channels = NULL; |
443 |
|
pClient->fxsends = NULL; |
444 |
pClient->midi_instruments = NULL; |
pClient->midi_instruments = NULL; |
445 |
pClient->midi_maps = NULL; |
pClient->midi_maps = NULL; |
446 |
pClient->midi_map_name = NULL; |
pClient->midi_map_name = NULL; |
1581 |
{ |
{ |
1582 |
char szQuery[LSCP_BUFSIZ]; |
char szQuery[LSCP_BUFSIZ]; |
1583 |
|
|
1584 |
if (iSamplerChannel < 0 || fVolume < 0.0) |
if (iSamplerChannel < 0 || fVolume < 0.0f) |
1585 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1586 |
|
|
1587 |
sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume); |
sprintf(szQuery, "SET CHANNEL VOLUME %d %g\r\n", iSamplerChannel, fVolume); |
1790 |
|
|
1791 |
|
|
1792 |
/** |
/** |
1793 |
|
* Get global volume attenuation: |
1794 |
|
* GET VOLUME |
1795 |
|
* |
1796 |
|
* @param pClient Pointer to client instance structure. |
1797 |
|
* |
1798 |
|
* @returns The global volume as positive floating point value usually in |
1799 |
|
* the range between 0.0 and 1.0; in case of failure 0.0 is returned. |
1800 |
|
*/ |
1801 |
|
float lscp_get_volume ( lscp_client_t *pClient ) |
1802 |
|
{ |
1803 |
|
float fVolume = 0.0f; |
1804 |
|
|
1805 |
|
if (pClient == NULL) |
1806 |
|
return 0.0f; |
1807 |
|
|
1808 |
|
// Lock this section up. |
1809 |
|
lscp_mutex_lock(pClient->mutex); |
1810 |
|
|
1811 |
|
if (lscp_client_call(pClient, "GET VOLUME\r\n", 0) == LSCP_OK) |
1812 |
|
fVolume = (float) atof(lscp_client_get_result(pClient)); |
1813 |
|
|
1814 |
|
// Unlock this section down. |
1815 |
|
lscp_mutex_unlock(pClient->mutex); |
1816 |
|
|
1817 |
|
return fVolume; |
1818 |
|
} |
1819 |
|
|
1820 |
|
|
1821 |
|
/** |
1822 |
|
* Setting global volume attenuation: |
1823 |
|
* SET VOLUME <volume> |
1824 |
|
* |
1825 |
|
* @param pClient Pointer to client instance structure. |
1826 |
|
* @param fVolume Global volume parameter as positive floating point |
1827 |
|
* value usually be in the range between 0.0 and 1.0, |
1828 |
|
* that is for attenuating the overall volume. |
1829 |
|
* |
1830 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1831 |
|
*/ |
1832 |
|
lscp_status_t lscp_set_volume ( lscp_client_t *pClient, float fVolume ) |
1833 |
|
{ |
1834 |
|
char szQuery[LSCP_BUFSIZ]; |
1835 |
|
|
1836 |
|
if (fVolume < 0.0f) |
1837 |
|
return LSCP_FAILED; |
1838 |
|
|
1839 |
|
sprintf(szQuery, "SET VOLUME %g\r\n", fVolume); |
1840 |
|
return lscp_client_query(pClient, szQuery); |
1841 |
|
} |
1842 |
|
|
1843 |
|
|
1844 |
|
/** |
1845 |
|
* Add an effect send to a sampler channel: |
1846 |
|
* CREATE FX_SEND <sampler-channel> <midi-ctrl> [<name>] |
1847 |
|
* |
1848 |
|
* @param pClient Pointer to client instance structure. |
1849 |
|
* @param iSamplerChannel Sampler channel number. |
1850 |
|
* @param iMidiController MIDI controller used to alter the effect, |
1851 |
|
* usually a number between 0 and 127. |
1852 |
|
* @param pszName Optional name for the effect send entity, |
1853 |
|
* does not have to be unique. |
1854 |
|
* |
1855 |
|
* @returns The new effect send number identifier, or -1 in case of failure. |
1856 |
|
*/ |
1857 |
|
int lscp_create_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iMidiController, const char *pszFxName ) |
1858 |
|
{ |
1859 |
|
int iFxSend = -1; |
1860 |
|
char szQuery[LSCP_BUFSIZ]; |
1861 |
|
|
1862 |
|
if (pClient == NULL) |
1863 |
|
return -1; |
1864 |
|
if (iSamplerChannel < 0 || iMidiController < 0 || iMidiController > 127) |
1865 |
|
return -1; |
1866 |
|
|
1867 |
|
// Lock this section up. |
1868 |
|
lscp_mutex_lock(pClient->mutex); |
1869 |
|
|
1870 |
|
sprintf(szQuery, "CREATE FX_SEND %d %d", iSamplerChannel, iMidiController); |
1871 |
|
|
1872 |
|
if (pszFxName) |
1873 |
|
sprintf(szQuery + strlen(szQuery), " '%s'", pszFxName); |
1874 |
|
|
1875 |
|
strcat(szQuery, "\r\n"); |
1876 |
|
|
1877 |
|
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) |
1878 |
|
iFxSend = atoi(lscp_client_get_result(pClient)); |
1879 |
|
|
1880 |
|
// Unlock this section down. |
1881 |
|
lscp_mutex_unlock(pClient->mutex); |
1882 |
|
|
1883 |
|
return iFxSend; |
1884 |
|
} |
1885 |
|
|
1886 |
|
|
1887 |
|
/** |
1888 |
|
* Remove an effect send from a sampler channel: |
1889 |
|
* DESTROY FX_SEND <sampler-channel> <fx-send-id> |
1890 |
|
* |
1891 |
|
* @param pClient Pointer to client instance structure. |
1892 |
|
* @param iSamplerChannel Sampler channel number. |
1893 |
|
* @param iFxSend Effect send number. |
1894 |
|
* |
1895 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
1896 |
|
*/ |
1897 |
|
lscp_status_t lscp_destroy_fxsend ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend ) |
1898 |
|
{ |
1899 |
|
char szQuery[LSCP_BUFSIZ]; |
1900 |
|
|
1901 |
|
if (iSamplerChannel < 0 || iFxSend < 0) |
1902 |
|
return LSCP_FAILED; |
1903 |
|
|
1904 |
|
sprintf(szQuery, "DESTROY FX_SEND %d %d\r\n", iSamplerChannel, iFxSend); |
1905 |
|
|
1906 |
|
return lscp_client_query(pClient, szQuery); |
1907 |
|
} |
1908 |
|
|
1909 |
|
|
1910 |
|
/** |
1911 |
|
* Get amount of effect sends on a sampler channel: |
1912 |
|
* GET FX_SENDS <sampler-channel> |
1913 |
|
* |
1914 |
|
* @param pClient Pointer to client instance structure. |
1915 |
|
* @param iSamplerChannel Sampler channel number. |
1916 |
|
* |
1917 |
|
* @returns The current total number of effect sends of the sampler channel |
1918 |
|
* on success, -1 otherwise. |
1919 |
|
*/ |
1920 |
|
int lscp_get_fxsends ( lscp_client_t *pClient, int iSamplerChannel ) |
1921 |
|
{ |
1922 |
|
int iFxSends = -1; |
1923 |
|
char szQuery[LSCP_BUFSIZ]; |
1924 |
|
|
1925 |
|
if (pClient == NULL) |
1926 |
|
return -1; |
1927 |
|
if (iSamplerChannel < 0) |
1928 |
|
return -1; |
1929 |
|
|
1930 |
|
// Lock this section up. |
1931 |
|
lscp_mutex_lock(pClient->mutex); |
1932 |
|
|
1933 |
|
sprintf(szQuery, "GET FX_SENDS %d\r\n", iSamplerChannel); |
1934 |
|
|
1935 |
|
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) |
1936 |
|
iFxSends = atoi(lscp_client_get_result(pClient)); |
1937 |
|
|
1938 |
|
// Unlock this section doen. |
1939 |
|
lscp_mutex_unlock(pClient->mutex); |
1940 |
|
|
1941 |
|
return iFxSends; |
1942 |
|
} |
1943 |
|
|
1944 |
|
|
1945 |
|
/** |
1946 |
|
* List all effect sends on a sampler channel: |
1947 |
|
* LIST FX_SENDS <sampler-channel> |
1948 |
|
* |
1949 |
|
* @param pClient Pointer to client instance structure. |
1950 |
|
* @param iSamplerChannel Sampler channel number. |
1951 |
|
* |
1952 |
|
* @returns An array of the effect sends identifiers as positive integers, |
1953 |
|
* terminated with -1 on success, NULL otherwise. |
1954 |
|
*/ |
1955 |
|
int *lscp_list_fxsends ( lscp_client_t *pClient, int iSamplerChannel ) |
1956 |
|
{ |
1957 |
|
const char *pszSeps = ","; |
1958 |
|
char szQuery[LSCP_BUFSIZ]; |
1959 |
|
|
1960 |
|
if (pClient == NULL) |
1961 |
|
return NULL; |
1962 |
|
|
1963 |
|
// Lock this section up. |
1964 |
|
lscp_mutex_lock(pClient->mutex); |
1965 |
|
|
1966 |
|
if (pClient->fxsends) { |
1967 |
|
lscp_isplit_destroy(pClient->fxsends); |
1968 |
|
pClient->fxsends = NULL; |
1969 |
|
} |
1970 |
|
|
1971 |
|
sprintf(szQuery, "LIST FX_SENDS %d\r\n", iSamplerChannel); |
1972 |
|
|
1973 |
|
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) |
1974 |
|
pClient->fxsends = lscp_isplit_create(lscp_client_get_result(pClient), pszSeps); |
1975 |
|
|
1976 |
|
// Unlock this section down. |
1977 |
|
lscp_mutex_unlock(pClient->mutex); |
1978 |
|
|
1979 |
|
return pClient->fxsends; |
1980 |
|
} |
1981 |
|
|
1982 |
|
|
1983 |
|
/** |
1984 |
|
* Getting effect send information |
1985 |
|
* GET FX_SEND INFO <sampler-channel> <fx-send-id> |
1986 |
|
* |
1987 |
|
* @param pClient Pointer to client instance structure. |
1988 |
|
* @param iSamplerChannel Sampler channel number. |
1989 |
|
* @param iFxSend Effect send number. |
1990 |
|
* |
1991 |
|
* @returns A pointer to a @ref lscp_fxsend_info_t structure, with the |
1992 |
|
* information of the given FX send, or NULL in case of failure. |
1993 |
|
*/ |
1994 |
|
lscp_fxsend_info_t *lscp_get_fxsend_info ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend ) |
1995 |
|
{ |
1996 |
|
lscp_fxsend_info_t *pFxSendInfo; |
1997 |
|
char szQuery[LSCP_BUFSIZ]; |
1998 |
|
const char *pszResult; |
1999 |
|
const char *pszSeps = ":"; |
2000 |
|
const char *pszCrlf = "\r\n"; |
2001 |
|
char *pszToken; |
2002 |
|
char *pch; |
2003 |
|
|
2004 |
|
if (pClient == NULL) |
2005 |
|
return NULL; |
2006 |
|
if (iSamplerChannel < 0 || iFxSend < 0) |
2007 |
|
return NULL; |
2008 |
|
|
2009 |
|
// Lock this section up. |
2010 |
|
lscp_mutex_lock(pClient->mutex); |
2011 |
|
|
2012 |
|
pFxSendInfo = &(pClient->fxsend_info); |
2013 |
|
lscp_fxsend_info_reset(pFxSendInfo); |
2014 |
|
|
2015 |
|
sprintf(szQuery, "GET FX_SEND INFO %d %d\r\n", iSamplerChannel, iFxSend); |
2016 |
|
if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) { |
2017 |
|
pszResult = lscp_client_get_result(pClient); |
2018 |
|
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
2019 |
|
while (pszToken) { |
2020 |
|
if (strcasecmp(pszToken, "NAME") == 0) { |
2021 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2022 |
|
if (pszToken) |
2023 |
|
lscp_unquote_dup(&(pFxSendInfo->name), &pszToken); |
2024 |
|
} |
2025 |
|
else if (strcasecmp(pszToken, "MIDI_CONTROLLER") == 0) { |
2026 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2027 |
|
if (pszToken) |
2028 |
|
pFxSendInfo->midi_controller = atoi(lscp_ltrim(pszToken)); |
2029 |
|
} |
2030 |
|
else if (strcasecmp(pszToken, "AUDIO_OUTPUT_ROUTING") == 0) { |
2031 |
|
pszToken = lscp_strtok(NULL, pszCrlf, &(pch)); |
2032 |
|
if (pszToken) { |
2033 |
|
if (pFxSendInfo->audio_routing) |
2034 |
|
lscp_szsplit_destroy(pFxSendInfo->audio_routing); |
2035 |
|
pFxSendInfo->audio_routing = lscp_szsplit_create(pszToken, ","); |
2036 |
|
} |
2037 |
|
} |
2038 |
|
pszToken = lscp_strtok(NULL, pszSeps, &(pch)); |
2039 |
|
} |
2040 |
|
} |
2041 |
|
else pFxSendInfo = NULL; |
2042 |
|
|
2043 |
|
// Unlock this section up. |
2044 |
|
lscp_mutex_unlock(pClient->mutex); |
2045 |
|
|
2046 |
|
return pFxSendInfo; |
2047 |
|
} |
2048 |
|
|
2049 |
|
|
2050 |
|
/** |
2051 |
|
* Alter effect send's audio routing: |
2052 |
|
* SET FX_SEND AUDIO_OUTPUT_CHANNEL <sampler-chan> <fx-send-id> |
2053 |
|
* <audio-src> <audio-dst> |
2054 |
|
* |
2055 |
|
* @param pClient Pointer to client instance structure. |
2056 |
|
* @param iSamplerChannel Sampler channel number. |
2057 |
|
* @param iFxSend Effect send number. |
2058 |
|
* @param iAudioSrc Audio output device channel to be routed from. |
2059 |
|
* @param iAudioDst Audio output device channel to be routed into. |
2060 |
|
* |
2061 |
|
* @returns LSCP_OK on success, LSCP_FAILED otherwise. |
2062 |
|
*/ |
2063 |
|
lscp_status_t lscp_set_fxsend_audio_channel ( lscp_client_t *pClient, int iSamplerChannel, int iFxSend, int iAudioSrc, int iAudioDst ) |
2064 |
|
{ |
2065 |
|
char szQuery[LSCP_BUFSIZ]; |
2066 |
|
|
2067 |
|
if (iSamplerChannel < 0 || iFxSend < 0 || iAudioSrc < 0 || iAudioDst < 0) |
2068 |
|
return LSCP_FAILED; |
2069 |
|
|
2070 |
|
sprintf(szQuery, "SET FX_SEND AUDIO_OUTPUT_CHANNEL %d %d %d %d\r\n", iSamplerChannel, iFxSend, iAudioSrc, iAudioDst); |
2071 |
|
return lscp_client_query(pClient, szQuery); |
2072 |
|
} |
2073 |
|
|
2074 |
|
|
2075 |
|
/** |
2076 |
* Create a new MIDI instrument map: |
* Create a new MIDI instrument map: |
2077 |
* ADD MIDI_INSTRUMENT_MAP [<name>] |
* ADD MIDI_INSTRUMENT_MAP [<name>] |
2078 |
* |
* |
2227 |
} |
} |
2228 |
|
|
2229 |
sprintf(szQuery, "GET MIDI_INSTRUMENT_MAP INFO %d\r\n", iMidiMap); |
sprintf(szQuery, "GET MIDI_INSTRUMENT_MAP INFO %d\r\n", iMidiMap); |
2230 |
if (lscp_client_call(pClient, szQuery, 0) == LSCP_OK) { |
if (lscp_client_call(pClient, szQuery, 1) == LSCP_OK) { |
2231 |
pszResult = lscp_client_get_result(pClient); |
pszResult = lscp_client_get_result(pClient); |
2232 |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
pszToken = lscp_strtok((char *) pszResult, pszSeps, &(pch)); |
2233 |
while (pszToken) { |
while (pszToken) { |