Skip to content

Commit 1c90cf2

Browse files
committed
add jamulusclient/setInstrumentCode JSONRPC method
1 parent 3cbe00b commit 1c90cf2

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

docs/JSON-RPC.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,23 @@ Results:
274274
| result | string | Always "ok". |
275275

276276

277+
### jamulusclient/setInstrumentCode
278+
279+
Sets your instrument code.
280+
281+
Parameters:
282+
283+
| Name | Type | Description |
284+
| --- | --- | --- |
285+
| params.instrCode | number | The new instrument code. |
286+
287+
Results:
288+
289+
| Name | Type | Description |
290+
| --- | --- | --- |
291+
| result | string | Always "ok". |
292+
293+
277294
### jamulusclient/setMidiSettings
278295

279296
Sets one or more MIDI controller settings.

src/clientrpc.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,32 @@ CClientRpc::CClientRpc ( CClient* pClient, CClientSettings* pSettings, CRpcServe
331331
response["result"] = "ok";
332332
} );
333333

334+
/// @rpc_method jamulusclient/setInstrumentCode
335+
/// @brief Sets your instrument code.
336+
/// @param {number} params.instrCode - The new instrument code.
337+
/// @result {string} result - Always "ok".
338+
pRpcServer->HandleMethod ( "jamulusclient/setInstrumentCode", [=] ( const QJsonObject& params, QJsonObject& response ) {
339+
auto jsonInstrCode = params["instrCode"];
340+
341+
if ( !jsonInstrCode.isDouble() )
342+
{
343+
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: instrCode is not a number" );
344+
return;
345+
}
346+
347+
const int _iInstrument = jsonInstrCode.toInt();
348+
349+
if ( CInstPictures::GetName ( _iInstrument ).isEmpty() )
350+
{
351+
response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: unknown instrCode" );
352+
return;
353+
}
354+
355+
pClient->ChannelInfo.iInstrument = _iInstrument;
356+
pClient->SetRemoteInfo();
357+
response["result"] = "ok";
358+
} );
359+
334360
/// @rpc_method jamulusclient/sendChatText
335361
/// @brief Sends a chat text message.
336362
/// @param {string} params.chatText - The chat text message.

0 commit comments

Comments
 (0)