Browse Source

Make CarlaHost API C compatible as well

tags/1.9.4
falkTX 11 years ago
parent
commit
393e0eccee
6 changed files with 127 additions and 142 deletions
  1. +3
    -3
      source/backend/CarlaBackend.h
  2. +86
    -109
      source/backend/CarlaHost.h
  3. +23
    -23
      source/carla_backend.py
  4. +10
    -3
      source/includes/CarlaDefines.h
  5. +4
    -4
      source/tests/Makefile
  6. +1
    -0
      source/tests/ansi-pedantic-test.c

+ 3
- 3
source/backend/CarlaBackend.h View File

@@ -15,8 +15,8 @@
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#ifndef CARLA_BACKEND_HPP_INCLUDED
#define CARLA_BACKEND_HPP_INCLUDED
#ifndef CARLA_BACKEND_H_INCLUDED
#define CARLA_BACKEND_H_INCLUDED

#include "CarlaDefines.h"

@@ -1270,4 +1270,4 @@ class CarlaPlugin;
CARLA_BACKEND_END_NAMESPACE
#endif

#endif /* CARLA_BACKEND_HPP_INCLUDED */
#endif /* CARLA_BACKEND_H_INCLUDED */

+ 86
- 109
source/backend/CarlaHost.h View File

@@ -15,10 +15,28 @@
* For a full copy of the GNU General Public License see the doc/GPL.txt file.
*/

#ifndef CARLA_HOST_HPP_INCLUDED
#define CARLA_HOST_HPP_INCLUDED

#include "CarlaBackend.hpp"
#ifndef CARLA_HOST_H_INCLUDED
#define CARLA_HOST_H_INCLUDED

#include "CarlaBackend.h"

#ifdef __cplusplus
using CarlaBackend::BinaryType;
using CarlaBackend::PluginType;
using CarlaBackend::PluginCategory;
using CarlaBackend::InternalParameterIndex;
using CarlaBackend::EngineCallbackOpcode;
using CarlaBackend::EngineOption;
using CarlaBackend::EngineProcessMode;
using CarlaBackend::EngineTransportMode;
using CarlaBackend::EngineCallbackFunc;
using CarlaBackend::ParameterData;
using CarlaBackend::ParameterRanges;
using CarlaBackend::MidiProgramData;
using CarlaBackend::CustomData;
using CarlaBackend::EngineDriverDeviceInfo;
using CarlaBackend::CarlaEngine;
#endif

/*!
* @defgroup CarlaHostAPI Carla Host API
@@ -34,27 +52,6 @@
* @{
*/

/*!
* @defgroup HelperTypedefs Helper typedefs
*
* Basic typedefs to help make code cleaner.
* @{
*/
typedef CarlaBackend::BinaryType CarlaBinaryType;
typedef CarlaBackend::PluginType CarlaPluginType;
typedef CarlaBackend::PluginCategory CarlaPluginCategory;
typedef CarlaBackend::EngineCallbackFunc CarlaEngineCallbackFunc;
typedef CarlaBackend::EngineCallbackOpcode CarlaEngineCallbackOpcode;
typedef CarlaBackend::EngineOption CarlaEngineOption;
typedef CarlaBackend::FileCallbackFunc CarlaFileCallbackFunc;
typedef CarlaBackend::FileCallbackOpcode CarlaFileCallbackOpcode;
typedef CarlaBackend::ParameterData CarlaParameterData;
typedef CarlaBackend::ParameterRanges CarlaParameterRanges;
typedef CarlaBackend::MidiProgramData CarlaMidiProgramData;
typedef CarlaBackend::CustomData CarlaCustomData;
typedef CarlaBackend::EngineDriverDeviceInfo CarlaEngineDriverDeviceInfo;
/**@}*/

/*!
* File callback opcodes.\n
* Front-ends must always block-wait for user input.
@@ -81,17 +78,17 @@ typedef enum {

/*!
* File callback function.
* @see FileCallbackType
* @see FileCallbackOpcode
*/
typedef const char* (*FileCallbackFunc)(void* ptr, FileCallbackOpcode action, bool isDir, const char* title, const char* filter);

/*!
* Plugin information.
* \see carla_get_plugin_info()
* @see carla_get_plugin_info()
*/
struct CarlaPluginInfo {
CarlaPluginType type;
CarlaPluginCategory category;
typedef struct _CarlaPluginInfo {
PluginType type;
PluginCategory category;
unsigned int hints;
unsigned int optionsAvailable;
unsigned int optionsEnabled;
@@ -104,8 +101,8 @@ struct CarlaPluginInfo {
int patchbayClientId;
long uniqueId;

#ifndef DOXYGEN
CarlaPluginInfo()
#ifdef __cplusplus
_CarlaPluginInfo()
: type(CarlaBackend::PLUGIN_NONE),
category(CarlaBackend::PLUGIN_CATEGORY_NONE),
hints(0x0),
@@ -120,7 +117,7 @@ struct CarlaPluginInfo {
patchbayClientId(0),
uniqueId(0) {}

~CarlaPluginInfo()
~_CarlaPluginInfo()
{
if (label != nullptr)
{
@@ -139,14 +136,14 @@ struct CarlaPluginInfo {
}
}
#endif
};
} CarlaPluginInfo;

/*!
* Native plugin information.
* \see carla_get_internal_plugin_info()
* @see carla_get_internal_plugin_info()
*/
struct CarlaNativePluginInfo {
CarlaPluginCategory category;
typedef struct _CarlaNativePluginInfo {
PluginCategory category;
unsigned int hints;
uint32_t audioIns;
uint32_t audioOuts;
@@ -159,8 +156,8 @@ struct CarlaNativePluginInfo {
const char* maker;
const char* copyright;

#ifndef DOXYGEN
CarlaNativePluginInfo()
#ifdef __cplusplus
_CarlaNativePluginInfo()
: category(CarlaBackend::PLUGIN_CATEGORY_NONE),
hints(0x0),
audioIns(0),
@@ -174,45 +171,45 @@ struct CarlaNativePluginInfo {
maker(nullptr),
copyright(nullptr) {}
#endif
};
} CarlaNativePluginInfo;

/*!
* Port count information, used for Audio and MIDI ports and parameters.
* \see carla_get_audio_port_count_info()
* \see carla_get_midi_port_count_info()
* \see carla_get_parameter_count_info()
* @see carla_get_audio_port_count_info()
* @see carla_get_midi_port_count_info()
* @see carla_get_parameter_count_info()
*/
struct CarlaPortCountInfo {
typedef struct _CarlaPortCountInfo {
uint32_t ins;
uint32_t outs;
uint32_t total;

#ifndef DOXYGEN
CarlaPortCountInfo()
#ifdef __cplusplus
_CarlaPortCountInfo()
: ins(0),
outs(0),
total(0) {}
#endif
};
} CarlaPortCountInfo;

/*!
* Parameter information.
* \see carla_get_parameter_info()
* @see carla_get_parameter_info()
*/
struct CarlaParameterInfo {
typedef struct _CarlaParameterInfo {
const char* name;
const char* symbol;
const char* unit;
uint32_t scalePointCount;

#ifndef DOXYGEN
CarlaParameterInfo()
#ifdef __cplusplus
_CarlaParameterInfo()
: name(nullptr),
symbol(nullptr),
unit(nullptr),
scalePointCount(0) {}

~CarlaParameterInfo()
~_CarlaParameterInfo()
{
if (name != nullptr)
{
@@ -231,22 +228,22 @@ struct CarlaParameterInfo {
}
}
#endif
};
} CarlaParameterInfo;

/*!
* Parameter scale point information.
* \see carla_get_parameter_scalepoint_info()
* @see carla_get_parameter_scalepoint_info()
*/
struct CarlaScalePointInfo {
typedef struct _CarlaScalePointInfo {
float value;
const char* label;

#ifndef DOXYGEN
CarlaScalePointInfo()
#ifdef __cplusplus
_CarlaScalePointInfo()
: value(0.0f),
label(nullptr) {}

~CarlaScalePointInfo()
~_CarlaScalePointInfo()
{
if (label != nullptr)
{
@@ -255,13 +252,13 @@ struct CarlaScalePointInfo {
}
}
#endif
};
} CarlaScalePointInfo;

/*!
* Transport information.
* \see carla_get_transport_info()
* @see carla_get_transport_info()
*/
struct CarlaTransportInfo {
typedef struct _CarlaTransportInfo {
bool playing;
uint64_t frame;
int32_t bar;
@@ -269,8 +266,8 @@ struct CarlaTransportInfo {
int32_t tick;
double bpm;

#ifndef DOXYGEN
CarlaTransportInfo()
#ifdef __cplusplus
_CarlaTransportInfo()
: playing(false),
frame(0),
bar(0),
@@ -278,7 +275,7 @@ struct CarlaTransportInfo {
tick(0),
bpm(0.0) {}
#endif
};
} CarlaTransportInfo;

/*!
* Get the complete license text of used third-party code and features.\n
@@ -313,7 +310,7 @@ CARLA_EXPORT const char* const* carla_get_engine_driver_device_names(unsigned in
/*!
* Get a device driver info.
*/
CARLA_EXPORT const CarlaEngineDriverDeviceInfo* carla_get_engine_driver_device_info(unsigned int index, const char* driverName);
CARLA_EXPORT const EngineDriverDeviceInfo* carla_get_engine_driver_device_info(unsigned int index, const char* driverName);

/*!
* Get how many internal plugins are available to use.
@@ -325,6 +322,13 @@ CARLA_EXPORT unsigned int carla_get_internal_plugin_count();
*/
CARLA_EXPORT const CarlaNativePluginInfo* carla_get_internal_plugin_info(unsigned int internalPluginId);

#ifdef __cplusplus
/*!
* TODO.
*/
CARLA_EXPORT CarlaEngine* carla_get_standalone_engine();
#endif

/*!
* Initialize the engine with driver \a driverName, using \a clientName for its internal name.\n
* Make sure to call carla_engine_idle() at regular intervals afterwards.
@@ -366,26 +370,26 @@ CARLA_EXPORT void carla_set_engine_about_to_close();
* Set the engine callback function to \a func.
* Use \a ptr to pass a custom pointer to the callback.
*/
CARLA_EXPORT void carla_set_engine_callback(CarlaEngineCallbackFunc func, void* ptr);
CARLA_EXPORT void carla_set_engine_callback(EngineCallbackFunc func, void* ptr);

/*!
* Set the engine option \a option.\n
* With the exception of OPTION_PROCESS_NAME, OPTION_TRANSPORT_MODE and OPTION_PATH_*,
* this function should not be called when the engine is running.
*/
CARLA_EXPORT void carla_set_engine_option(CarlaEngineOption option, int value, const char* valueStr);
CARLA_EXPORT void carla_set_engine_option(EngineOption option, int value, const char* valueStr);

/*!
* Set the file callback function to \a func.
* Use \a ptr to pass a custom pointer to the callback.
*/
CARLA_EXPORT void carla_set_file_callback(CarlaFileCallbackFunc func, void* ptr);
CARLA_EXPORT void carla_set_file_callback(FileCallbackFunc func, void* ptr);

/*!
* Load \a filename of any type.\n
* This will try to load a generic file as a plugin,
* either by direct handling (GIG, SF2 and SFZ) or by using an internal plugin (like Audio and MIDI).
* \see carla_get_supported_file_types()
* @see carla_get_supported_file_types()
*/
CARLA_EXPORT bool carla_load_filename(const char* filename);

@@ -446,7 +450,7 @@ CARLA_EXPORT const CarlaTransportInfo* carla_get_transport_info();
* Add new plugin.\n
* If you don't know the binary type, use BINARY_NATIVE.
*/
CARLA_EXPORT bool carla_add_plugin(CarlaBinaryType btype, CarlaPluginType ptype, const char* filename, const char* name, const char* label, const void* extraPtr);
CARLA_EXPORT bool carla_add_plugin(BinaryType btype, PluginType ptype, const char* filename, const char* name, const char* label, const void* extraPtr);

/*!
* Remove plugin with id \a pluginId.
@@ -484,14 +488,14 @@ CARLA_EXPORT bool carla_switch_plugins(unsigned int pluginIdA, unsigned int plug
/*!
* Load the plugin state at \a filename.\n
* (Plugin states have *.carxs extension).
* \see carla_save_plugin_state()
* @see carla_save_plugin_state()
*/
CARLA_EXPORT bool carla_load_plugin_state(unsigned int pluginId, const char* filename);

/*!
* Load the plugin state at \a filename.\n
* (Plugin states have *.carxs extension).
* \see carla_load_plugin_state()
* @see carla_load_plugin_state()
*/
CARLA_EXPORT bool carla_save_plugin_state(unsigned int pluginId, const char* filename);

@@ -528,22 +532,22 @@ CARLA_EXPORT const CarlaScalePointInfo* carla_get_parameter_scalepoint_info(unsi
/*!
* Get a plugin's parameter data.
*/
CARLA_EXPORT const CarlaParameterData* carla_get_parameter_data(unsigned int pluginId, uint32_t parameterId);
CARLA_EXPORT const ParameterData* carla_get_parameter_data(unsigned int pluginId, uint32_t parameterId);

/*!
* Get a plugin's parameter ranges.
*/
CARLA_EXPORT const CarlaParameterRanges* carla_get_parameter_ranges(unsigned int pluginId, uint32_t parameterId);
CARLA_EXPORT const ParameterRanges* carla_get_parameter_ranges(unsigned int pluginId, uint32_t parameterId);

/*!
* Get a plugin's midi program data.
*/
CARLA_EXPORT const CarlaMidiProgramData* carla_get_midi_program_data(unsigned int pluginId, uint32_t midiProgramId);
CARLA_EXPORT const MidiProgramData* carla_get_midi_program_data(unsigned int pluginId, uint32_t midiProgramId);

/*!
* Get a plugin's custom data.
*/
CARLA_EXPORT const CarlaCustomData* carla_get_custom_data(unsigned int pluginId, uint32_t customDataId);
CARLA_EXPORT const CustomData* carla_get_custom_data(unsigned int pluginId, uint32_t customDataId);

/*!
* Get a plugin's chunk data.
@@ -567,13 +571,13 @@ CARLA_EXPORT uint32_t carla_get_midi_program_count(unsigned int pluginId);

/*!
* Get how many custom data sets a plugin has.
* \see carla_prepare_for_save()
* @see carla_prepare_for_save()
*/
CARLA_EXPORT uint32_t carla_get_custom_data_count(unsigned int pluginId);

/*!
* Get a plugin's custom parameter text display.
* \see PARAMETER_USES_CUSTOM_TEXT
* @see PARAMETER_USES_CUSTOM_TEXT
*/
CARLA_EXPORT const char* carla_get_parameter_text(unsigned int pluginId, uint32_t parameterId);

@@ -627,7 +631,7 @@ CARLA_EXPORT float carla_get_output_peak_value(unsigned int pluginId, unsigned s

/*!
* Enable a plugin's option.
* \see PluginOptions
* @see PluginOptions
*/
CARLA_EXPORT void carla_set_option(unsigned int pluginId, unsigned int option, bool yesNo);

@@ -721,7 +725,7 @@ CARLA_EXPORT void carla_send_midi_note(unsigned int pluginId, uint8_t channel, u

/*!
* Tell a plugin to show its own custom UI.
* \see PLUGIN_HAS_CUSTOM_UI
* @see PLUGIN_HAS_CUSTOM_UI
*/
CARLA_EXPORT void carla_show_custom_ui(unsigned int pluginId, bool yesNo);

@@ -750,33 +754,6 @@ CARLA_EXPORT const char* carla_get_host_osc_url_tcp();
*/
CARLA_EXPORT const char* carla_get_host_osc_url_udp();

/*!
* Send NSM announce message.
*/
CARLA_EXPORT void carla_nsm_announce(const char* url, const char* appName, int pid);

/*!
* Ready for handling NSM messages.
*/
CARLA_EXPORT void carla_nsm_ready();

/*!
* Reply to NSM open message.
* \see CALLBACK_NSM_OPEN
*/
CARLA_EXPORT void carla_nsm_reply_open();

/*!
* Reply to NSM save message.
* \see CALLBACK_NSM_SAVE
*/
CARLA_EXPORT void carla_nsm_reply_save();

#ifdef BUILD_BRIDGE
using CarlaBackend::CarlaEngine;
CARLA_EXPORT CarlaEngine* carla_get_standalone_engine();
#endif

/**@}*/
/** @} */

#endif // CARLA_HOST_HPP_INCLUDED
#endif // CARLA_HOST_H_INCLUDED

+ 23
- 23
source/carla_backend.py View File

@@ -809,29 +809,24 @@ PyEngineDriverDeviceInfo = {
}

# ------------------------------------------------------------------------------------------------------------
# Set BINARY_NATIVE
# File Callback Opcode

if HAIKU or LINUX or MACOS:
BINARY_NATIVE = BINARY_POSIX64 if kIs64bit else BINARY_POSIX32
elif WINDOWS:
BINARY_NATIVE = BINARY_WIN64 if kIs64bit else BINARY_WIN32
else:
BINARY_NATIVE = BINARY_OTHER

# ------------------------------------------------------------------------------------------------------------
# Backend C++ -> Python variables
# Debug.
# This opcode is undefined and used only for testing purposes.
FILE_CALLBACK_DEBUG = 0

FileCallbackFunc = CFUNCTYPE(c_char_p, c_void_p, c_enum, c_bool, c_char_p, c_char_p)
# Open file or folder.
FILE_CALLBACK_OPEN = 1

# ------------------------------------------------------------------------------------------------------------
# Host C++ -> Python variables
# Save file or folder.
FILE_CALLBACK_SAVE = 2

# ------------------------------------------------------------------------------------------------------------
# File Callback Type
# Carla Host API (C stuff)

FILE_CALLBACK_DEBUG = 0
FILE_CALLBACK_OPEN = 1
FILE_CALLBACK_SAVE = 2
# File callback function.
# @see FileCallbackOpcode
FileCallbackFunc = CFUNCTYPE(c_char_p, c_void_p, c_enum, c_bool, c_char_p, c_char_p)

class CarlaPluginInfo(Structure):
_fields_ = [
@@ -898,7 +893,7 @@ class CarlaTransportInfo(Structure):
]

# ------------------------------------------------------------------------------------------------------------
# Python object dicts compatible with ctypes struct
# Carla Host API (Python compatible stuff)

PyCarlaPluginInfo = {
'type': PLUGIN_NONE,
@@ -943,13 +938,18 @@ PyCarlaTransportInfo = {
"bpm": 0.0
}

PyCarlaEngineDriverInfo = {
"name": None,
"hints": 0x0
}
# ------------------------------------------------------------------------------------------------------------
# Set BINARY_NATIVE

if HAIKU or LINUX or MACOS:
BINARY_NATIVE = BINARY_POSIX64 if kIs64bit else BINARY_POSIX32
elif WINDOWS:
BINARY_NATIVE = BINARY_WIN64 if kIs64bit else BINARY_WIN32
else:
BINARY_NATIVE = BINARY_OTHER

# ------------------------------------------------------------------------------------------------------------
# Host Python object (Control/Standalone)
# Python Host object (Control/Standalone)

class Host(object):
def __init__(self, libName):


+ 10
- 3
source/includes/CarlaDefines.h View File

@@ -189,14 +189,21 @@ private: \
static void operator delete(void*);
#endif

/* Define EXTERN_C */
#ifdef __cplusplus
# define EXTERN_C extern "C"
#else
# define EXTERN_C
#endif

/* Define CARLA_EXPORT */
#ifdef BUILD_BRIDGE
# define CARLA_EXPORT extern "C"
# define CARLA_EXPORT EXTERN_C
#else
# if defined(CARLA_OS_WIN) && ! defined(__WINE__)
# define CARLA_EXPORT extern "C" __declspec (dllexport)
# define CARLA_EXPORT EXTERN_C __declspec (dllexport)
# else
# define CARLA_EXPORT extern "C" __attribute__ ((visibility("default")))
# define CARLA_EXPORT EXTERN_C __attribute__ ((visibility("default")))
# endif
#endif



+ 4
- 4
source/tests/Makefile View File

@@ -39,16 +39,16 @@ all: $(TARGETS)

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

ansi-pedantic-test_c: ansi-pedantic-test.c ../backend/CarlaBackend.h
ansi-pedantic-test_c: ansi-pedantic-test.c ../backend/Carla*.h
$(CC) $< $(ANSI_FLAGS) -Wc++-compat -o $@

ansi-pedantic-test_c99: ansi-pedantic-test.c ../backend/CarlaBackend.h
ansi-pedantic-test_c99: ansi-pedantic-test.c ../backend/Carla*.h
$(CC) $< $(ANSI_FLAGS) -std=c99 -Wc++-compat -o $@

ansi-pedantic-test_cxx: ansi-pedantic-test.c ../backend/CarlaBackend.h
ansi-pedantic-test_cxx: ansi-pedantic-test.c ../backend/Carla*.h
$(CXX) $< $(ANSI_FLAGS) -o $@

ansi-pedantic-test_cxx11: ansi-pedantic-test.c ../backend/CarlaBackend.h
ansi-pedantic-test_cxx11: ansi-pedantic-test.c ../backend/Carla*.h
$(CXX) $< $(ANSI_FLAGS) -std=c++11 -Wzero-as-null-pointer-constant -o $@

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


+ 1
- 0
source/tests/ansi-pedantic-test.c View File

@@ -16,6 +16,7 @@
*/

#include "CarlaBackend.h"
#include "CarlaHost.h"

int main(int argc, char* argv[])
{


Loading…
Cancel
Save