Browse Source

Initial working communication for REST server/client

tags/v1.9.11
falkTX 6 years ago
parent
commit
3f486b4385
11 changed files with 544 additions and 196 deletions
  1. +1
    -5
      .gitignore
  2. +64
    -0
      source/carla-rest-frontend
  3. +1
    -1
      source/carla_backend.py
  4. +74
    -0
      source/carla_backend_qtweb.py
  5. +4
    -4
      source/rest/Makefile
  6. +138
    -0
      source/rest/buffers.cpp
  7. +37
    -0
      source/rest/buffers.hpp
  8. +77
    -0
      source/rest/carla-host.cpp
  9. +91
    -0
      source/rest/carla-utils.cpp
  10. +37
    -0
      source/rest/common.hpp
  11. +20
    -186
      source/rest/rest-server.cpp

+ 1
- 5
.gitignore View File

@@ -93,12 +93,8 @@ carla-discovery-native
carla-discovery-posix32 carla-discovery-posix32
carla-discovery-posix64 carla-discovery-posix64


carla-frontend
carla-lv2-export carla-lv2-export

zita-at1-ui
zita-bls1-ui
zita-rev1-ui
carla-rest-server
zynaddsubfx-ui zynaddsubfx-ui


stoat-output.png stoat-output.png


+ 64
- 0
source/carla-rest-frontend View File

@@ -0,0 +1,64 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Carla plugin host
# Copyright (C) 2011-2018 Filipe Coelho <falktx@falktx.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For a full copy of the GNU General Public License see the doc/GPL.txt file.

# ----------------------------------------------------------------------------------------------------------------------
# Imports (Custom Stuff)

from carla_backend_qtweb import CarlaHostQtWeb
from carla_host import (
CarlaApplication,
HostWindow,
setUpSignals,
initHost,
loadHostSettings,
)

# ----------------------------------------------------------------------------------------------------------------------
# Main

if __name__ == '__main__':
# ------------------------------------------------------------------------------------------------------------------
# App initialization

app = CarlaApplication("Carla2-REST")

# ------------------------------------------------------------------------------------------------------------------
# Set-up custom signal handling

setUpSignals()

# ------------------------------------------------------------------------------------------------------------------
# Init host backend

host = initHost("Carla-REST", None, False, False, False, CarlaHostQtWeb)
loadHostSettings(host)

# ------------------------------------------------------------------------------------------------------------------
# Create GUI

gui = HostWindow(host, True)

# ------------------------------------------------------------------------------------------------------------------
# Show GUI

gui.show()

# ------------------------------------------------------------------------------------------------------------------
# App-Loop

app.exit_exec()

+ 1
- 1
source/carla_backend.py View File

@@ -1911,7 +1911,7 @@ class CarlaHostNull(CarlaHostMeta):
return return


def is_engine_running(self): def is_engine_running(self):
return False
return self.fEngineRunning


def set_engine_about_to_close(self): def set_engine_about_to_close(self):
return True return True


+ 74
- 0
source/carla_backend_qtweb.py View File

@@ -0,0 +1,74 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Carla Backend code (Web stuff)
# Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# For a full copy of the GNU General Public License see the doc/GPL.txt file.

# ---------------------------------------------------------------------------------------------------------------------
# Imports (Global)

import requests

# ---------------------------------------------------------------------------------------------------------------------
# Imports (Custom)

from carla_backend_qt import *

# ---------------------------------------------------------------------------------------------------------------------
# Carla Host object for connecting to the REST API

class CarlaHostQtWeb(CarlaHostQtNull):
def __init__(self):
CarlaHostQtNull.__init__(self)

self.baseurl = "http://localhost:2228"

def get_engine_driver_count(self):
# FIXME
return int(requests.get("{}/get_engine_driver_count".format(self.baseurl)).text) - 1

def get_engine_driver_name(self, index):
return requests.get("{}/get_engine_driver_name/{}".format(self.baseurl, index)).text

def get_engine_driver_device_names(self, index):
# FIXME strip should not be needed
return requests.get("{}/get_engine_driver_device_names/{}".format(self.baseurl, index)).text.strip().split("\n")

def get_engine_driver_device_info(self, index, name):
return requests.get("{}/get_engine_driver_device_info/{}/{}".format(self.baseurl, index, name)).json()

# ---------------------------------------------------------------------------------------------------------------------
# TESTING

if __name__ == '__main__':

baseurl = "http://localhost:2228"

driver_count = int(requests.get("{}/get_engine_driver_count".format(baseurl)).text)

# FIXME
driver_count -= 1

print("Driver names:")
for index in range(driver_count):
print("\t -", requests.get("{}/get_engine_driver_name/{}".format(baseurl, index)).text)

print("Driver device names:")
# FIXME strip should not be needed
for index in range(driver_count):
for name in requests.get("{}/get_engine_driver_device_names/{}".format(baseurl, index)).text.strip().split("\n"):
print("\t {}:".format(name), requests.get("{}/get_engine_driver_device_info/{}/{}".format(baseurl, index, name)).json())

# ---------------------------------------------------------------------------------------------------------------------

+ 4
- 4
source/rest/Makefile View File

@@ -23,7 +23,7 @@ endif


BUILD_CXX_FLAGS += -I$(CWD) -I$(CWD)/backend -I$(CWD)/includes -I$(CWD)/modules -I$(CWD)/utils BUILD_CXX_FLAGS += -I$(CWD) -I$(CWD)/backend -I$(CWD)/includes -I$(CWD)/modules -I$(CWD)/utils


LINK_FLAGS += -L$(BINDIR) -lcarla_utils -lrestbed -Wl,-rpath=$(shell realpath $(CWD)/../bin)
LINK_FLAGS += -L$(BINDIR) -lcarla_standalone2 -lcarla_utils -lrestbed -Wl,-rpath=$(shell realpath $(CWD)/../bin)


# ---------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------


@@ -44,14 +44,14 @@ debug:


# ---------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------


$(BINDIR)/carla-rest-server: $(OBJDIR)/rest-server.cpp.o
$(BINDIR)/carla-rest-server: $(OBJDIR)/rest-server.cpp.o $(OBJDIR)/buffers.cpp.o
-@mkdir -p $(BINDIR) -@mkdir -p $(BINDIR)
@echo "Linking carla-rest-server" @echo "Linking carla-rest-server"
@$(CXX) $< $(LINK_FLAGS) -o $@
@$(CXX) $^ $(LINK_FLAGS) -o $@


# ---------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------


$(OBJDIR)/rest-server.cpp.o: rest-server.cpp
$(OBJDIR)/%.cpp.o: %.cpp
-@mkdir -p $(OBJDIR) -@mkdir -p $(OBJDIR)
@echo "Compiling $<" @echo "Compiling $<"
@$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@ @$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@


+ 138
- 0
source/rest/buffers.cpp View File

@@ -0,0 +1,138 @@
/*
* Carla REST API Server
* Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#include "buffers.hpp"

#include <cstdio>
#include <cstring>

// -------------------------------------------------------------------------------------------------------------------

enum {
kJsonBufSize = 4095,
kStrBufSize = 1023,
kSizeBufSize = 31,
};

// static buffer to return json
// NOTE size is never checked for json, the buffer is big enough in order to assume it all always fits
static char jsonBuf[kJsonBufSize+1];

// static buffer to return size
static char sizeBuf[kSizeBufSize+1];

// static buffer to return regular strings
static char strBuf[kStrBufSize+1];

// -------------------------------------------------------------------------------------------------------------------

const char* size_buf(const char* const buf)
{
const std::size_t size = std::strlen(buf);
std::snprintf(sizeBuf, kSizeBufSize, P_SIZE, size);
sizeBuf[kSizeBufSize] = '\0';
return sizeBuf;
}

// -------------------------------------------------------------------------------------------------------------------

const char* str_buf_string(const char* const string)
{
std::strncpy(strBuf, string, kStrBufSize);
strBuf[kStrBufSize] = '\0';
return strBuf;
}

const char* str_buf_string_array(const char* const* const array)
{
size_t bytesRead = 0;

for (int i=0; array[i] != nullptr && bytesRead < kStrBufSize; ++i)
{
const std::size_t size = std::strlen(array[i]);

if (bytesRead + size > kStrBufSize)
break;

std::strncpy(strBuf+bytesRead, array[i], kStrBufSize);
bytesRead += size;
strBuf[bytesRead] = '\n';
bytesRead += 1;
}

strBuf[bytesRead] = '\0';
return strBuf;
}

const char* str_buf_uint(const uint value)
{
std::snprintf(strBuf, kStrBufSize, "%u", value);
strBuf[kStrBufSize] = '\0';
return strBuf;
}

// -------------------------------------------------------------------------------------------------------------------

char* json_buf_start()
{
std::strcpy(jsonBuf, "{");
return jsonBuf + 1;
}

template <typename T, typename Fn>
char* json_buf_add(char* jsonBufPtr, const char* const key, const T value, const Fn fn)
{
fn(value);

if (jsonBufPtr != jsonBuf+1)
{
*jsonBufPtr = ',';
jsonBufPtr += 1;
}

*jsonBufPtr++ = '"';

std::strcpy(jsonBufPtr, key);
jsonBufPtr += std::strlen(key);

*jsonBufPtr++ = '"';
*jsonBufPtr++ = ':';

std::strcpy(jsonBufPtr, strBuf);
jsonBufPtr += std::strlen(strBuf);

return jsonBufPtr;
}

char* json_buf_add_string(char* jsonBufPtr, const char* const key, const char* const value)
{
return json_buf_add(jsonBufPtr, key, value, str_buf_string);
}

char* json_buf_add_uint(char* jsonBufPtr, const char* const key, const uint value)
{
return json_buf_add(jsonBufPtr, key, value, str_buf_uint);
}

const char* json_buf_end(char* jsonBufPtr)
{
*jsonBufPtr++ = '}';
*jsonBufPtr++ = '\0';
return jsonBuf;
}

// -------------------------------------------------------------------------------------------------------------------

+ 37
- 0
source/rest/buffers.hpp View File

@@ -0,0 +1,37 @@
/*
* Carla REST API Server
* Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#ifndef REST_BUFFERS_HPP_INCLUDED
#define REST_BUFFERS_HPP_INCLUDED

#include "CarlaDefines.h"

// size buf
const char* size_buf(const char* const buf);

// base types
const char* str_buf_string(const char* const string);
const char* str_buf_string_array(const char* const* const array);
const char* str_buf_uint(const uint value);

// json
char* json_buf_start();
char* json_buf_add_string(char* jsonBufPtr, const char* const key, const char* const value);
char* json_buf_add_uint(char* jsonBufPtr, const char* const key, const uint value);
const char* json_buf_end(char* jsonBufPtr);

#endif // REST_BUFFERS_HPP_INCLUDED

+ 77
- 0
source/rest/carla-host.cpp View File

@@ -0,0 +1,77 @@
/*
* Carla REST API Server
* Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#include "common.hpp"

#include "CarlaHost.h"

// -------------------------------------------------------------------------------------------------------------------

void handle_carla_get_engine_driver_count(const std::shared_ptr<Session> session)
{
const char* const buf = str_buf_uint(carla_get_engine_driver_count());
session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
}

void handle_carla_get_engine_driver_name(const std::shared_ptr<Session> session)
{
const std::shared_ptr<const Request> request = session->get_request();

const int index = std::atoi(request->get_path_parameter("index").c_str());
CARLA_SAFE_ASSERT_RETURN(index >= 0 /*&& index < INT_MAX*/,)

const char* const buf = str_buf_string(carla_get_engine_driver_name(index));
session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
}

void handle_carla_get_engine_driver_device_names(const std::shared_ptr<Session> session)
{
const std::shared_ptr<const Request> request = session->get_request();

const int index = std::atoi(request->get_path_parameter("index").c_str());
CARLA_SAFE_ASSERT_RETURN(index >= 0 /*&& index < INT_MAX*/,)

const char* const buf = str_buf_string_array(carla_get_engine_driver_device_names(index));
session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
}

void handle_carla_get_engine_driver_device_info(const std::shared_ptr<Session> session)
{
const std::shared_ptr<const Request> request = session->get_request();

const int index = std::atoi(request->get_path_parameter("index").c_str());
CARLA_SAFE_ASSERT_RETURN(index >= 0 /*&& index < INT_MAX*/,)

const std::string name = request->get_path_parameter("name");

const EngineDriverDeviceInfo* const info = carla_get_engine_driver_device_info(index, name.c_str());

char* jsonBuf;
jsonBuf = json_buf_start();
jsonBuf = json_buf_add_uint(jsonBuf, "hints", info->hints);

// TODO
//jsonBuf = json_buf_add_uint(jsonBuf, "bufferSizes", info->bufferSizes);
//jsonBuf = json_buf_add_uint(jsonBuf, "sampleRates", info->sampleRates);

const char* const buf = json_buf_end(jsonBuf);
session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
}

// -------------------------------------------------------------------------------------------------------------------

// -------------------------------------------------------------------------------------------------------------------

+ 91
- 0
source/rest/carla-utils.cpp View File

@@ -0,0 +1,91 @@
/*
* Carla REST API Server
* Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#include "common.hpp"

#include "CarlaUtils.h"

// -------------------------------------------------------------------------------------------------------------------

void handle_carla_get_complete_license_text(const std::shared_ptr<Session> session)
{
const char* const buf = str_buf_string(carla_get_complete_license_text());
session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
}

void handle_carla_get_supported_file_extensions(const std::shared_ptr<Session> session)
{
const char* const buf = str_buf_string_array(carla_get_supported_file_extensions());
session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
}

void handle_carla_get_supported_features(const std::shared_ptr<Session> session)
{
const char* const buf = str_buf_string_array(carla_get_supported_features());
session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
}

void handle_carla_get_cached_plugin_count(const std::shared_ptr<Session> session)
{
const std::shared_ptr<const Request> request = session->get_request();

const int ptype = std::atoi(request->get_path_parameter("ptype").c_str());
CARLA_SAFE_ASSERT_RETURN(ptype >= PLUGIN_NONE && ptype <= PLUGIN_JACK,)

const std::string pluginPath = request->get_path_parameter("pluginPath");

const char* const buf = str_buf_uint(carla_get_cached_plugin_count(static_cast<PluginType>(ptype),
pluginPath.c_str()));
session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
}

void handle_carla_get_cached_plugin_info(const std::shared_ptr<Session> session)
{
const std::shared_ptr<const Request> request = session->get_request();

const int ptype = std::atoi(request->get_path_parameter("ptype").c_str());
CARLA_SAFE_ASSERT_RETURN(ptype >= PLUGIN_NONE && ptype <= PLUGIN_JACK,)

const int index = std::atoi(request->get_path_parameter("index").c_str());
CARLA_SAFE_ASSERT_RETURN(index >= 0 /*&& index < INT_MAX*/,)

// REMOVE THIS
carla_get_cached_plugin_count(static_cast<PluginType>(ptype), nullptr);

const CarlaCachedPluginInfo* const info = carla_get_cached_plugin_info(static_cast<PluginType>(ptype),
static_cast<uint>(index));

char* jsonBuf;
jsonBuf = json_buf_start();
jsonBuf = json_buf_add_uint(jsonBuf, "category", info->category);
jsonBuf = json_buf_add_uint(jsonBuf, "hints", info->hints);
jsonBuf = json_buf_add_uint(jsonBuf, "audioIns", info->audioIns);
jsonBuf = json_buf_add_uint(jsonBuf, "audioOuts", info->audioOuts);
jsonBuf = json_buf_add_uint(jsonBuf, "midiIns", info->midiIns);
jsonBuf = json_buf_add_uint(jsonBuf, "midiOuts", info->midiOuts);
jsonBuf = json_buf_add_uint(jsonBuf, "parameterIns", info->parameterIns);
jsonBuf = json_buf_add_uint(jsonBuf, "parameterOuts", info->parameterOuts);
jsonBuf = json_buf_add_string(jsonBuf, "name", info->name);
jsonBuf = json_buf_add_string(jsonBuf, "label", info->label);
jsonBuf = json_buf_add_string(jsonBuf, "maker", info->maker);
jsonBuf = json_buf_add_string(jsonBuf, "copyright", info->copyright);

const char* const buf = json_buf_end(jsonBuf);
session->close(OK, buf, { { "Content-Length", size_buf(buf) } } );
}

// -------------------------------------------------------------------------------------------------------------------

+ 37
- 0
source/rest/common.hpp View File

@@ -0,0 +1,37 @@
/*
* Carla REST API Server
* Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#ifndef REST_COMMON_HPP_INCLUDED
#define REST_COMMON_HPP_INCLUDED

#include "buffers.hpp"

#include "CarlaBackend.h"
#include "CarlaUtils.hpp"

#include <restbed>

using restbed::Request;
using restbed::Resource;
using restbed::Service;
using restbed::Session;
using restbed::Settings;
using restbed::OK;

CARLA_BACKEND_USE_NAMESPACE;

#endif // REST_COMMON_HPP_INCLUDED

+ 20
- 186
source/rest/rest-server.cpp View File

@@ -21,188 +21,12 @@
* Take this into consideration before deploying it to any servers. * Take this into consideration before deploying it to any servers.
*/ */


#include "CarlaHost.h"
#include "CarlaUtils.h"
#include "CarlaUtils.hpp"
#include "common.hpp"


#include <cstring>
#include <restbed>
#include "carla-host.cpp"
#include "carla-utils.cpp"


// #include <memory>
// #include <cstdlib>

// using namespace std;
using namespace restbed;

#if 0
void post_method_handler(const std::shared_ptr<Session> session)
{
const std::shared_ptr<const Request> request = session->get_request();

const string body = "Hello, " + request->get_path_parameter("id");
session->close(OK, body, { { "Content-Length", ::to_string( body.size( ) ) } } );
}
#endif

CARLA_BACKEND_START_NAMESPACE

enum {
kStrBufSize = 1023,
kJsonBufSize = 4095,
kSizeBufSize = 31,
};

// static buffer to returned content
static char strBuf[kStrBufSize+1];
static char jsonBuf[kJsonBufSize+1];

// static buffer to returned content size
static char sizeBuf[kSizeBufSize+1];

void prepare_size()
{
const std::size_t size = std::strlen(strBuf);
std::snprintf(sizeBuf, kSizeBufSize, P_SIZE, size);
sizeBuf[kSizeBufSize] = '\0';
}

void prepare_buffer_uint(const uint value)
{
std::snprintf(strBuf, kStrBufSize, "%u", value);
strBuf[kStrBufSize] = '\0';
}

void prepare_buffer_string(const char* const string)
{
std::strncpy(strBuf, string, kStrBufSize);
strBuf[kStrBufSize] = '\0';
}

void prepare_buffer_string_array(const char* const* const array)
{
size_t bytesRead = 0;
strBuf[0] = '\0';

for (int i=0; array[i] != nullptr && bytesRead < kStrBufSize; ++i)
{
const std::size_t size = std::strlen(array[i]);

if (bytesRead + size > kStrBufSize)
break;

std::strncpy(strBuf+bytesRead, array[i], kStrBufSize);
bytesRead += size;
strBuf[bytesRead] = '\n';
bytesRead += 1;
}

strBuf[bytesRead] = '\0';
}

char* prepare_buffer_json_start()
{
std::strcpy(jsonBuf, "{");
return jsonBuf + 1;
}

char* prepare_buffer_json_add_uint(char* bufPtr, const char* const key, const uint value)
{
prepare_buffer_uint(value);

if (bufPtr != jsonBuf+1)
{
*bufPtr = ',';
bufPtr += 1;
}

*bufPtr++ = '"';

std::strcpy(bufPtr, key);
bufPtr += std::strlen(key);

*bufPtr++ = '"';
*bufPtr++ = ':';

std::strcpy(bufPtr, strBuf);
bufPtr += std::strlen(strBuf);

return bufPtr;
}

void prepare_buffer_json_end(char* const bufPtr)
{
std::strcpy(bufPtr, "}");

const std::size_t size = std::strlen(jsonBuf);
std::snprintf(sizeBuf, kSizeBufSize, P_SIZE, size);
sizeBuf[kSizeBufSize] = '\0';
}

void handle_carla_get_complete_license_text(const std::shared_ptr<Session> session)
{
prepare_buffer_string(carla_get_complete_license_text());
prepare_size();
session->close(OK, strBuf, { { "Content-Length", sizeBuf } } );
}

void handle_carla_get_supported_file_extensions(const std::shared_ptr<Session> session)
{
prepare_buffer_string_array(carla_get_supported_file_extensions());
prepare_size();
session->close(OK, strBuf, { { "Content-Length", sizeBuf } } );
}

void handle_carla_get_supported_features(const std::shared_ptr<Session> session)
{
prepare_buffer_string_array(carla_get_supported_features());
prepare_size();
session->close(OK, strBuf, { { "Content-Length", sizeBuf } } );
}

void handle_carla_get_cached_plugin_count(const std::shared_ptr<Session> session)
{
PluginType ptype = PLUGIN_LV2;
const char* pluginPath = nullptr;

prepare_buffer_uint(carla_get_cached_plugin_count(ptype, pluginPath));
prepare_size();
session->close(OK, strBuf, { { "Content-Length", sizeBuf } } );
}

void handle_carla_get_cached_plugin_info(const std::shared_ptr<Session> session)
{
PluginType ptype = PLUGIN_LV2;
const uint index = 0;

// REMOVE THIS
carla_get_cached_plugin_count(ptype, nullptr);

const CarlaCachedPluginInfo* const info = carla_get_cached_plugin_info(ptype, index);

char* bufPtr;
bufPtr = prepare_buffer_json_start();
bufPtr = prepare_buffer_json_add_uint(bufPtr, "category", info->category);
bufPtr = prepare_buffer_json_add_uint(bufPtr, "hints", info->hints);
bufPtr = prepare_buffer_json_add_uint(bufPtr, "audioIns", info->audioIns);
bufPtr = prepare_buffer_json_add_uint(bufPtr, "audioOuts", info->audioOuts);
bufPtr = prepare_buffer_json_add_uint(bufPtr, "midiIns", info->midiIns);
bufPtr = prepare_buffer_json_add_uint(bufPtr, "midiOuts", info->midiOuts);
bufPtr = prepare_buffer_json_add_uint(bufPtr, "parameterIns", info->parameterIns);
bufPtr = prepare_buffer_json_add_uint(bufPtr, "parameterOuts", info->parameterOuts);

// const char* name;
// const char* label;
// const char* maker;
// const char* copyright;

prepare_buffer_json_end(bufPtr);

session->close(OK, jsonBuf, { { "Content-Length", sizeBuf } } );
}

// CARLA_EXPORT const CarlaCachedPluginInfo* carla_get_cached_plugin_info(PluginType ptype, uint index);

CARLA_BACKEND_END_NAMESPACE
// -------------------------------------------------------------------------------------------------------------------


void make_resource(Service& service, void make_resource(Service& service,
const char* const path, const char* const path,
@@ -214,16 +38,24 @@ void make_resource(Service& service,
service.publish(resource); service.publish(resource);
} }


// -------------------------------------------------------------------------------------------------------------------

int main(int, const char**) int main(int, const char**)
{ {
CARLA_BACKEND_USE_NAMESPACE;

Service service; Service service;
make_resource(service, "/get_complete_license_text", handle_carla_get_complete_license_text);

// carla-host
make_resource(service, "/get_engine_driver_count", handle_carla_get_engine_driver_count);
make_resource(service, "/get_engine_driver_name/{index: .*}", handle_carla_get_engine_driver_name);
make_resource(service, "/get_engine_driver_device_names/{index: .*}", handle_carla_get_engine_driver_device_names);
make_resource(service, "/get_engine_driver_device_info/{index: .*}/{name: .*}", handle_carla_get_engine_driver_device_info);

// carla-utils
make_resource(service, "/get_complete_license_text", handle_carla_get_complete_license_text);
make_resource(service, "/get_supported_file_extensions", handle_carla_get_supported_file_extensions); make_resource(service, "/get_supported_file_extensions", handle_carla_get_supported_file_extensions);
make_resource(service, "/get_supported_features", handle_carla_get_supported_features);
make_resource(service, "/get_cached_plugin_count", handle_carla_get_cached_plugin_count);
make_resource(service, "/get_cached_plugin_info", handle_carla_get_cached_plugin_info);
make_resource(service, "/get_supported_features", handle_carla_get_supported_features);
make_resource(service, "/get_cached_plugin_count/{ptype: .*}/{pluginPath: .*}", handle_carla_get_cached_plugin_count);
make_resource(service, "/get_cached_plugin_info/{ptype: .*}/{index: .*}", handle_carla_get_cached_plugin_info);


std::shared_ptr<Settings> settings = std::make_shared<Settings>(); std::shared_ptr<Settings> settings = std::make_shared<Settings>();
settings->set_port(2228); settings->set_port(2228);
@@ -233,3 +65,5 @@ int main(int, const char**)
service.start(settings); service.start(settings);
return 0; return 0;
} }

// -------------------------------------------------------------------------------------------------------------------

Loading…
Cancel
Save