LMMS
Loading...
Searching...
No Matches
carla-utils.cpp
Go to the documentation of this file.
1/*
2 * Carla REST API Server
3 * Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
16 */
17
18#include "common.hpp"
19
20#include "CarlaUtils.h"
21
22// -------------------------------------------------------------------------------------------------------------------
23
24void handle_carla_get_complete_license_text(const std::shared_ptr<Session> session)
25{
26 const char* const buf = str_buf_string(carla_get_complete_license_text());
27 session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
28}
29
30void handle_carla_get_supported_file_extensions(const std::shared_ptr<Session> session)
31{
33 session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
34}
35
36void handle_carla_get_supported_features(const std::shared_ptr<Session> session)
37{
38 const char* const buf = str_buf_string_array(carla_get_supported_features());
39 session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
40}
41
42void handle_carla_get_cached_plugin_count(const std::shared_ptr<Session> session)
43{
44 const std::shared_ptr<const Request> request = session->get_request();
45
46 const int ptype = std::atoi(request->get_query_parameter("ptype").c_str());
48
49 const std::string pluginPath = request->get_query_parameter("pluginPath");
50
51 const char* const buf = str_buf_uint(carla_get_cached_plugin_count(static_cast<PluginType>(ptype),
52 pluginPath.c_str()));
53 session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
54}
55
56void handle_carla_get_cached_plugin_info(const std::shared_ptr<Session> session)
57{
58 const std::shared_ptr<const Request> request = session->get_request();
59
60 const int ptype = std::atoi(request->get_query_parameter("ptype").c_str());
62
63 const int index = std::atoi(request->get_query_parameter("index").c_str());
64 CARLA_SAFE_ASSERT_RETURN(index >= 0 /*&& index < INT_MAX*/,)
65
66 const CarlaCachedPluginInfo* const info = carla_get_cached_plugin_info(static_cast<PluginType>(ptype),
67 static_cast<uint>(index));
68
69 char* jsonBuf;
71 jsonBuf = json_buf_add_bool(jsonBuf, "valid", info->valid);
72 jsonBuf = json_buf_add_uint(jsonBuf, "category", info->category);
73 jsonBuf = json_buf_add_uint(jsonBuf, "hints", info->hints);
74 jsonBuf = json_buf_add_uint(jsonBuf, "audioIns", info->audioIns);
75 jsonBuf = json_buf_add_uint(jsonBuf, "audioOuts", info->audioOuts);
76 jsonBuf = json_buf_add_uint(jsonBuf, "midiIns", info->midiIns);
77 jsonBuf = json_buf_add_uint(jsonBuf, "midiOuts", info->midiOuts);
78 jsonBuf = json_buf_add_uint(jsonBuf, "parameterIns", info->parameterIns);
79 jsonBuf = json_buf_add_uint(jsonBuf, "parameterOuts", info->parameterOuts);
80 jsonBuf = json_buf_add_string(jsonBuf, "name", info->name);
81 jsonBuf = json_buf_add_string(jsonBuf, "label", info->label);
82 jsonBuf = json_buf_add_string(jsonBuf, "maker", info->maker);
83 jsonBuf = json_buf_add_string(jsonBuf, "copyright", info->copyright);
84
85 const char* const buf = json_buf_end(jsonBuf);
86 session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
87}
88
89// -------------------------------------------------------------------------------------------------------------------
#define CARLA_SAFE_ASSERT_RETURN(cond, ret)
Definition CarlaDefines.h:190
unsigned int uint
Definition CarlaDefines.h:327
const char * str_buf_uint(const uint value)
Definition buffers.cpp:178
char * json_buf_start()
Definition buffers.cpp:219
const char * json_buf_end(char *jsonBufPtr)
Definition buffers.cpp:305
const char * str_buf_string_array(const char *const *const array)
Definition buffers.cpp:104
char * json_buf_add_uint(char *jsonBufPtr, const char *const key, const uint value)
Definition buffers.cpp:290
const char * str_buf_string(const char *const string)
Definition buffers.cpp:97
static char jsonBuf[kJsonBufSize+1]
Definition buffers.cpp:34
char * json_buf_add_bool(char *jsonBufPtr, const char *const key, const bool value)
Definition buffers.cpp:258
char * json_buf_add_string(char *jsonBufPtr, const char *const key, const char *const value)
Definition buffers.cpp:275
const char * size_buf(const char *const buf)
Definition buffers.cpp:44
void handle_carla_get_supported_features(const std::shared_ptr< Session > session)
Definition carla-utils.cpp:36
void handle_carla_get_supported_file_extensions(const std::shared_ptr< Session > session)
Definition carla-utils.cpp:30
void handle_carla_get_cached_plugin_count(const std::shared_ptr< Session > session)
Definition carla-utils.cpp:42
void handle_carla_get_complete_license_text(const std::shared_ptr< Session > session)
Definition carla-utils.cpp:24
void handle_carla_get_cached_plugin_info(const std::shared_ptr< Session > session)
Definition carla-utils.cpp:56
PluginType
Definition CarlaBackend.h:614
@ PLUGIN_JACK
Definition CarlaBackend.h:679
@ PLUGIN_NONE
Definition CarlaBackend.h:618
CARLA_API_EXPORT const char * carla_get_complete_license_text(void)
Definition Information.cpp:33
CARLA_API_EXPORT const char *const * carla_get_supported_file_extensions(void)
Definition Information.cpp:118
CARLA_API_EXPORT const char *const * carla_get_supported_features(void)
Definition Information.cpp:180
struct _CarlaCachedPluginInfo CarlaCachedPluginInfo
CARLA_PLUGIN_EXPORT uint carla_get_cached_plugin_count(PluginType ptype, const char *pluginPath)
CARLA_PLUGIN_EXPORT const CarlaCachedPluginInfo * carla_get_cached_plugin_info(PluginType ptype, uint index)
struct backing_store_struct * info
Definition jmemsys.h:183
zoff_t request
Definition extract.c:1037