diff --git a/docs/JSON-RPC.md b/docs/JSON-RPC.md index e9111187f4..48e2398e3f 100644 --- a/docs/JSON-RPC.md +++ b/docs/JSON-RPC.md @@ -274,6 +274,23 @@ Results: | result | string | Always "ok". | +### jamulusclient/setInstrumentCode + +Sets your instrument code. + +Parameters: + +| Name | Type | Description | +| --- | --- | --- | +| params.instrCode | number | The new instrument code. | + +Results: + +| Name | Type | Description | +| --- | --- | --- | +| result | string | Always "ok". | + + ### jamulusclient/setMidiSettings Sets one or more MIDI controller settings. diff --git a/src/clientrpc.cpp b/src/clientrpc.cpp index 9ba7060a1d..3d8865f138 100644 --- a/src/clientrpc.cpp +++ b/src/clientrpc.cpp @@ -331,6 +331,32 @@ CClientRpc::CClientRpc ( CClient* pClient, CClientSettings* pSettings, CRpcServe response["result"] = "ok"; } ); + /// @rpc_method jamulusclient/setInstrumentCode + /// @brief Sets your instrument code. + /// @param {number} params.instrCode - The new instrument code. + /// @result {string} result - Always "ok". + pRpcServer->HandleMethod ( "jamulusclient/setInstrumentCode", [=] ( const QJsonObject& params, QJsonObject& response ) { + auto jsonInstrCode = params["instrCode"]; + + if ( !jsonInstrCode.isDouble() ) + { + response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: instrCode is not a number" ); + return; + } + + const int _iInstrument = jsonInstrCode.toInt(); + + if ( CInstPictures::GetName ( _iInstrument ).isEmpty() ) + { + response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: unknown instrCode" ); + return; + } + + pClient->ChannelInfo.iInstrument = _iInstrument; + pClient->SetRemoteInfo(); + response["result"] = "ok"; + } ); + /// @rpc_method jamulusclient/sendChatText /// @brief Sends a chat text message. /// @param {string} params.chatText - The chat text message.