DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

component.h (3493B)


      1 /*
      2  * travesty, pure C VST3-compatible interface
      3  * Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
      4  *
      5  * Permission to use, copy, modify, and/or distribute this software for any purpose with
      6  * or without fee is hereby granted, provided that the above copyright notice and this
      7  * permission notice appear in all copies.
      8  *
      9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
     10  * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
     11  * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
     12  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
     13  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
     14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     15  */
     16 
     17 #pragma once
     18 
     19 #include "base.h"
     20 #include "bstream.h"
     21 
     22 #include "align_push.h"
     23 
     24 /**
     25  * buses
     26  */
     27 
     28 enum v3_media_types {
     29 	V3_AUDIO = 0,
     30 	V3_EVENT
     31 };
     32 
     33 static inline
     34 const char* v3_media_type_str(int32_t type)
     35 {
     36 	switch (type)
     37 	{
     38 	case V3_AUDIO:
     39 		return "V3_AUDIO";
     40 	case V3_EVENT:
     41 		return "V3_EVENT";
     42 	default:
     43 		return "[unknown]";
     44 	}
     45 }
     46 
     47 enum v3_bus_direction {
     48 	V3_INPUT = 0,
     49 	V3_OUTPUT
     50 };
     51 
     52 static inline
     53 const char* v3_bus_direction_str(int32_t d)
     54 {
     55 	switch (d)
     56 	{
     57 	case V3_INPUT:
     58 		return "V3_INPUT";
     59 	case V3_OUTPUT:
     60 		return "V3_OUTPUT";
     61 	default:
     62 		return "[unknown]";
     63 	}
     64 }
     65 
     66 enum v3_bus_types {
     67 	V3_MAIN = 0,
     68 	V3_AUX
     69 };
     70 
     71 enum v3_bus_flags {
     72 	V3_DEFAULT_ACTIVE     = 1 << 0,
     73 	V3_IS_CONTROL_VOLTAGE = 1 << 1
     74 };
     75 
     76 enum v3_io_mode {
     77 	V3_SIMPLE = 0,
     78 	V3_ADVANCED,
     79 	V3_OFFLINE_PROCESSING
     80 };
     81 
     82 struct v3_bus_info {
     83 	int32_t media_type;
     84 	int32_t direction;
     85 	int32_t channel_count;
     86 	v3_str_128 bus_name;
     87 	int32_t bus_type;
     88 	uint32_t flags;
     89 };
     90 
     91 struct v3_routing_info {
     92 	int32_t media_type;
     93 	int32_t bus_idx;
     94 	int32_t channel;
     95 };
     96 
     97 /**
     98  * component
     99  */
    100 
    101 struct v3_component {
    102 #ifndef __cplusplus
    103 	struct v3_plugin_base;
    104 #endif
    105 	v3_result (V3_API *get_controller_class_id)(void* self, v3_tuid class_id);
    106 	v3_result (V3_API *set_io_mode)(void* self, int32_t io_mode);
    107 	int32_t (V3_API *get_bus_count)(void* self, int32_t media_type, int32_t bus_direction);
    108 	v3_result (V3_API *get_bus_info)(void* self, int32_t media_type, int32_t bus_direction,
    109                                      int32_t bus_idx, struct v3_bus_info* bus_info);
    110 	v3_result (V3_API *get_routing_info)(void* self, struct v3_routing_info* input, struct v3_routing_info* output);
    111 	v3_result (V3_API *activate_bus)(void* self, int32_t media_type, int32_t bus_direction,
    112                                      int32_t bus_idx, v3_bool state);
    113 	v3_result (V3_API *set_active)(void* self, v3_bool state);
    114 	v3_result (V3_API *set_state)(void* self, struct v3_bstream **);
    115 	v3_result (V3_API *get_state)(void* self, struct v3_bstream **);
    116 };
    117 
    118 static constexpr const v3_tuid v3_component_iid =
    119 	V3_ID(0xE831FF31, 0xF2D54301, 0x928EBBEE, 0x25697802);
    120 
    121 #ifdef __cplusplus
    122 
    123 /**
    124  * C++ variants
    125  */
    126 
    127 struct v3_component_cpp : v3_funknown {
    128 	v3_plugin_base base;
    129 	v3_component comp;
    130 };
    131 
    132 template<> inline
    133 constexpr v3_component* v3_cpp_obj(v3_component** obj)
    134 {
    135 	/**
    136 	 * this ugly piece of code is required due to C++ assuming `reinterpret_cast` by default,
    137 	 * but we need everything to be `static_cast` for it to be `constexpr` compatible.
    138 	 */
    139 	return static_cast<v3_component*>(
    140 		static_cast<void*>(static_cast<uint8_t*>(static_cast<void*>(*obj)) + sizeof(void*)*5));
    141 }
    142 
    143 #endif
    144 
    145 #include "align_pop.h"