csound-curl : simple HTTP GET and POST requests from Csound
Overview
csound-curl provides opcodes to perform basic HTTP GET and POST requests at init time and k-rate. SSL hosts are supported. It can be used with the csound-json plugin opcodes in order to effectively communicate with web services and such.
Requirements
- Cmake >= 2.8.12
- Csound with development headers >= 6.14.0
- libCURL >= 7.26.0
Installation
Create a build directory at the top of the source tree, execute cmake .., make and optionally make install as root. If the latter is not used/possible then the resulting library can be used with the --opcode-lib flag in Csound. eg:
mkdir build && cd build
cmake ..
make && sudo make install
Cmake should find Csound and any other required libraries using the modules in the cmake/Modules directory and installation should be as simple as above.
Examples
Some examples are provided in the examples directory.
Opcode reference
Due to possible delays incurred by network processes, the init-time opcodes may interrupt any current activity in Csound. For example, audio may be subject to dropouts. As a result it may be ideal only to use the init time opcodes at performance initialisation, and use the k-rate opcodes if requests are required during performance.
ires, Sres curlget Surl
Perform a GET request at init time.
- ires : HTTP response code
-
Sres : response body
-
Surl : URL to request
ires, Sres curlpost Surl, SpostData
Perform a POST request at init time.
- ires : HTTP response code
-
Sres : response body
-
Surl : URL to request
- SpostData : data to post, should be URL encoded if required
kdone, kres, Sres curlgetk Surl
Perform a GET request at k-rate.
- kdone : trigger to specify if the request has completed (1 if so, 0 at all other times)
- kres : HTTP response code
-
Sres : response body
-
Surl : URL to request
kdone, kres, Sres curlpostk Surl, SpostData
Perform a POST request at k-rate.
- kdone : trigger to specify if the request has completed (1 if so, 0 at all other times)
- kres : HTTP response code
-
Sres : response body
-
Surl : URL to request
- SpostData : data to post, should be URL encoded if required
Sencoded curlurlencode Sinput
URL encode a string at init time.
-
Sinput : the string to be encoded
-
Sencoded : the encoded string
Sencoded curlurlencodek Sinput, ktrigger
URL encode a string at k-rate upon receipt of a trigger.
- Sinput : the string to be encoded
-
ktrigger : encode the string when this is set to 1
-
Sencoded : the encoded string