Collection of tools useful for audio production
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

182 lines
5.6KB

  1. /*
  2. * Carla Native Plugin API
  3. * Copyright (C) 2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #ifndef CARLA_NATIVE_H
  18. #define CARLA_NATIVE_H
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #else
  22. #include <stdbool.h>
  23. #endif
  24. #include <stddef.h>
  25. #include <stdint.h>
  26. typedef void* HostHandle;
  27. typedef void* PluginHandle;
  28. const uint32_t PLUGIN_IS_SYNTH = 1 << 0;
  29. const uint32_t PLUGIN_HAS_GUI = 1 << 1;
  30. const uint32_t PLUGIN_USES_SINGLE_THREAD = 1 << 2;
  31. const uint32_t PORT_HINT_IS_OUTPUT = 1 << 0;
  32. const uint32_t PORT_HINT_IS_ENABLED = 1 << 1;
  33. const uint32_t PORT_HINT_IS_AUTOMABLE = 1 << 2;
  34. const uint32_t PORT_HINT_IS_BOOLEAN = 1 << 3;
  35. const uint32_t PORT_HINT_IS_INTEGER = 1 << 4;
  36. const uint32_t PORT_HINT_IS_LOGARITHMIC = 1 << 5;
  37. const uint32_t PORT_HINT_USES_SAMPLE_RATE = 1 << 6;
  38. const uint32_t PORT_HINT_USES_SCALEPOINTS = 1 << 7;
  39. const uint32_t PORT_HINT_USES_CUSTOM_TEXT = 1 << 8;
  40. typedef enum _PluginCategory {
  41. PLUGIN_CATEGORY_NONE = 0, //!< Null plugin category.
  42. PLUGIN_CATEGORY_SYNTH = 1, //!< A synthesizer or generator.
  43. PLUGIN_CATEGORY_DELAY = 2, //!< A delay or reverberator.
  44. PLUGIN_CATEGORY_EQ = 3, //!< An equalizer.
  45. PLUGIN_CATEGORY_FILTER = 4, //!< A filter.
  46. PLUGIN_CATEGORY_DYNAMICS = 5, //!< A 'dynamic' plugin (amplifier, compressor, gate, etc).
  47. PLUGIN_CATEGORY_MODULATOR = 6, //!< A 'modulator' plugin (chorus, flanger, phaser, etc).
  48. PLUGIN_CATEGORY_UTILITY = 7, //!< An 'utility' plugin (analyzer, converter, mixer, etc).
  49. PLUGIN_CATEGORY_OTHER = 8 //!< Misc plugin (used to check if the plugin has a category).
  50. } PluginCategory;
  51. typedef enum _PortType {
  52. PORT_TYPE_NULL = 0,
  53. PORT_TYPE_AUDIO = 1,
  54. PORT_TYPE_MIDI = 2,
  55. PORT_TYPE_PARAMETER = 3
  56. } PortType;
  57. typedef struct _ParameterRanges {
  58. double def;
  59. double min;
  60. double max;
  61. double step;
  62. double stepSmall;
  63. double stepLarge;
  64. } ParameterRanges;
  65. typedef struct _MidiEvent {
  66. uint32_t portOffset;
  67. uint32_t time;
  68. uint8_t size;
  69. uint8_t data[4];
  70. } MidiEvent;
  71. typedef struct _MidiProgram {
  72. uint32_t bank;
  73. uint32_t program;
  74. const char* name;
  75. } MidiProgram;
  76. typedef struct _TimeInfoBBT {
  77. int32_t bar;
  78. int32_t beat;
  79. int32_t tick;
  80. double bar_start_tick;
  81. float beats_per_bar;
  82. float beat_type;
  83. double ticks_per_beat;
  84. double beats_per_minute;
  85. } TimeInfoBBT;
  86. typedef struct _TimeInfo {
  87. bool playing;
  88. uint32_t frame;
  89. uint32_t time;
  90. uint32_t valid;
  91. TimeInfoBBT bbt;
  92. } TimeInfo;
  93. typedef struct _HostDescriptor {
  94. HostHandle handle;
  95. uint32_t (*get_buffer_size)(HostHandle handle);
  96. double (*get_sample_rate)(HostHandle handle);
  97. const TimeInfo* (*get_time_info)(HostHandle handle);
  98. bool (*write_midi_event)(HostHandle handle, MidiEvent* event);
  99. } HostDescriptor;
  100. typedef struct _PluginPortScalePoint {
  101. const char* label;
  102. double value;
  103. } PluginPortScalePoint;
  104. typedef struct _PluginPort {
  105. PortType type;
  106. uint32_t hints;
  107. const char* name;
  108. uint32_t scalePointCount;
  109. PluginPortScalePoint* scalePoints;
  110. } PluginPort;
  111. typedef struct _PluginDescriptor {
  112. PluginCategory category;
  113. uint32_t hints;
  114. const char* name;
  115. const char* label;
  116. const char* maker;
  117. const char* copyright;
  118. uint32_t portCount;
  119. PluginPort* ports;
  120. uint32_t midiProgramCount;
  121. MidiProgram* midiPrograms;
  122. PluginHandle (*instantiate)(struct _PluginDescriptor* _this_, HostDescriptor* host);
  123. void (*activate)(PluginHandle handle);
  124. void (*deactivate)(PluginHandle handle);
  125. void (*cleanup)(PluginHandle handle);
  126. void (*get_parameter_ranges)(PluginHandle handle, uint32_t index, ParameterRanges* ranges);
  127. double (*get_parameter_value)(PluginHandle handle, uint32_t index);
  128. const char* (*get_parameter_text)(PluginHandle handle, uint32_t index);
  129. const char* (*get_parameter_unit)(PluginHandle handle, uint32_t index);
  130. void (*set_parameter_value)(PluginHandle handle, uint32_t index, double value);
  131. void (*set_midi_program)(PluginHandle handle, uint32_t bank, uint32_t program);
  132. void (*set_custom_data)(PluginHandle handle, const char* key, const char* value);
  133. void (*show_gui)(PluginHandle handle, bool show);
  134. void (*idle_gui)(PluginHandle handle);
  135. // TODO - ui_set_*
  136. void (*process)(PluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, uint32_t midiEventCount, MidiEvent* midiEvents);
  137. void* _singleton;
  138. void (*_init)(struct _PluginDescriptor* _this_);
  139. void (*_fini)(struct _PluginDescriptor* _this_);
  140. } PluginDescriptor;
  141. // -----------------------------------------------------------------------
  142. void carla_register_native_plugin(const PluginDescriptor* desc);
  143. #define CARLA_REGISTER_NATIVE_PLUGIN(label, desc) \
  144. void carla_register_native_plugin_##label () __attribute__((constructor)); \
  145. void carla_register_native_plugin_##label () { carla_register_native_plugin(&desc); }
  146. #ifdef __cplusplus
  147. } /* extern "C" */
  148. #endif
  149. #endif // CARLA_NATIVE_H