Fix last commit
[carla.git] / source / rest / carla-utils.cpp
blobe2bf4f37dad356bc16e08ea71f65c1cf0ca8da0b
1 /*
2 * Carla REST API Server
3 * Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
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.
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.
15 * For a full copy of the GNU General Public License see the doc/GPL.txt file.
18 #include "common.hpp"
20 #include "CarlaUtils.h"
22 // -------------------------------------------------------------------------------------------------------------------
24 void handle_carla_get_complete_license_text(const std::shared_ptr<Session> session)
26 const char* const buf = str_buf_string(carla_get_complete_license_text());
27 session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
30 void handle_carla_get_supported_file_extensions(const std::shared_ptr<Session> session)
32 const char* const buf = str_buf_string_array(carla_get_supported_file_extensions());
33 session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
36 void handle_carla_get_supported_features(const std::shared_ptr<Session> session)
38 const char* const buf = str_buf_string_array(carla_get_supported_features());
39 session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
42 void handle_carla_get_cached_plugin_count(const std::shared_ptr<Session> session)
44 const std::shared_ptr<const Request> request = session->get_request();
46 const int ptype = std::atoi(request->get_query_parameter("ptype").c_str());
47 CARLA_SAFE_ASSERT_RETURN(ptype >= PLUGIN_NONE && ptype <= PLUGIN_JACK,)
49 const std::string pluginPath = request->get_query_parameter("pluginPath");
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) } } );
56 void handle_carla_get_cached_plugin_info(const std::shared_ptr<Session> session)
58 const std::shared_ptr<const Request> request = session->get_request();
60 const int ptype = std::atoi(request->get_query_parameter("ptype").c_str());
61 CARLA_SAFE_ASSERT_RETURN(ptype >= PLUGIN_NONE && ptype <= PLUGIN_JACK,)
63 const int index = std::atoi(request->get_query_parameter("index").c_str());
64 CARLA_SAFE_ASSERT_RETURN(index >= 0 /*&& index < INT_MAX*/,)
66 const CarlaCachedPluginInfo* const info = carla_get_cached_plugin_info(static_cast<PluginType>(ptype),
67 static_cast<uint>(index));
69 char* jsonBuf;
70 jsonBuf = json_buf_start();
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);
85 const char* const buf = json_buf_end(jsonBuf);
86 session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
89 // -------------------------------------------------------------------------------------------------------------------