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.

187 lines
5.8KB

  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* PluginHandle;
  27. const uint32_t PLUGIN_IS_SYNTH = 1 << 0;
  28. const uint32_t PLUGIN_HAS_GUI = 1 << 1;
  29. const uint32_t PLUGIN_USES_SINGLE_THREAD = 1 << 2;
  30. const uint32_t PORT_HINT_IS_OUTPUT = 1 << 0;
  31. const uint32_t PORT_HINT_IS_ENABLED = 1 << 1;
  32. const uint32_t PORT_HINT_IS_AUTOMABLE = 1 << 2;
  33. const uint32_t PORT_HINT_IS_BOOLEAN = 1 << 3;
  34. const uint32_t PORT_HINT_IS_INTEGER = 1 << 4;
  35. const uint32_t PORT_HINT_IS_LOGARITHMIC = 1 << 5;
  36. const uint32_t PORT_HINT_USES_SAMPLE_RATE = 1 << 6;
  37. const uint32_t PORT_HINT_USES_SCALEPOINTS = 1 << 7;
  38. const uint32_t PORT_HINT_USES_CUSTOM_TEXT = 1 << 8;
  39. typedef enum _PluginCategory {
  40. PLUGIN_CATEGORY_NONE = 0, //!< Null plugin category.
  41. PLUGIN_CATEGORY_SYNTH = 1, //!< A synthesizer or generator.
  42. PLUGIN_CATEGORY_DELAY = 2, //!< A delay or reverberator.
  43. PLUGIN_CATEGORY_EQ = 3, //!< An equalizer.
  44. PLUGIN_CATEGORY_FILTER = 4, //!< A filter.
  45. PLUGIN_CATEGORY_DYNAMICS = 5, //!< A 'dynamic' plugin (amplifier, compressor, gate, etc).
  46. PLUGIN_CATEGORY_MODULATOR = 6, //!< A 'modulator' plugin (chorus, flanger, phaser, etc).
  47. PLUGIN_CATEGORY_UTILITY = 7, //!< An 'utility' plugin (analyzer, converter, mixer, etc).
  48. PLUGIN_CATEGORY_OTHER = 8 //!< Misc plugin (used to check if the plugin has a category).
  49. } PluginCategory;
  50. typedef enum _PortType {
  51. PORT_TYPE_NULL = 0,
  52. PORT_TYPE_AUDIO = 1,
  53. PORT_TYPE_MIDI = 2,
  54. PORT_TYPE_PARAMETER = 3
  55. } PortType;
  56. typedef struct _ParameterRanges {
  57. double def;
  58. double min;
  59. double max;
  60. double step;
  61. double stepSmall;
  62. double stepLarge;
  63. } ParameterRanges;
  64. typedef struct _MidiEvent {
  65. uint32_t time;
  66. uint8_t size;
  67. uint8_t data[4];
  68. } MidiEvent;
  69. typedef struct _MidiProgram {
  70. uint32_t bank;
  71. uint32_t program;
  72. const char* name;
  73. } MidiProgram;
  74. typedef struct _TimeInfoBBT {
  75. int32_t bar;
  76. int32_t beat;
  77. int32_t tick;
  78. double bar_start_tick;
  79. float beats_per_bar;
  80. float beat_type;
  81. double ticks_per_beat;
  82. double beats_per_minute;
  83. } TimeInfoBBT;
  84. typedef struct _TimeInfo {
  85. bool playing;
  86. uint32_t frame;
  87. uint32_t time;
  88. uint32_t valid;
  89. TimeInfoBBT bbt;
  90. } TimeInfo;
  91. typedef struct _PluginPortScalePoint {
  92. const char* label;
  93. double value;
  94. } PluginPortScalePoint;
  95. typedef struct _PluginPort {
  96. PortType type;
  97. uint32_t hints;
  98. const char* name;
  99. uint32_t scalePointCount;
  100. PluginPortScalePoint* scalePoints;
  101. } PluginPort;
  102. typedef struct _PluginDescriptor {
  103. PluginCategory category;
  104. uint32_t hints;
  105. const char* name;
  106. const char* label;
  107. const char* maker;
  108. const char* copyright;
  109. uint32_t portCount;
  110. PluginPort* ports;
  111. uint32_t midiProgramCount;
  112. MidiProgram* midiPrograms;
  113. PluginHandle (*instantiate)(struct _PluginDescriptor* _this_);
  114. void (*activate)(PluginHandle handle);
  115. void (*deactivate)(PluginHandle handle);
  116. void (*cleanup)(PluginHandle handle);
  117. void (*get_parameter_ranges)(PluginHandle handle, uint32_t index, ParameterRanges* ranges);
  118. double (*get_parameter_value)(PluginHandle handle, uint32_t index);
  119. const char* (*get_parameter_text)(PluginHandle handle, uint32_t index);
  120. const char* (*get_parameter_unit)(PluginHandle handle, uint32_t index);
  121. void (*set_parameter_value)(PluginHandle handle, uint32_t index, double value);
  122. void (*set_midi_program)(PluginHandle handle, uint32_t bank, uint32_t program);
  123. void (*set_custom_data)(PluginHandle handle, const char* key, const char* value);
  124. void (*show_gui)(PluginHandle handle, bool show);
  125. void (*idle_gui)(PluginHandle handle);
  126. // TODO - ui_set_*
  127. void (*process)(PluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, uint32_t midiEventCount, MidiEvent* midiEvents);
  128. // TODO - midi stuff^
  129. PluginHandle _handle;
  130. void (*_init)(struct _PluginDescriptor* _this_);
  131. void (*_fini)(struct _PluginDescriptor* _this_);
  132. } PluginDescriptor;
  133. // -----------------------------------------------------------------------
  134. void carla_register_native_plugin(const PluginDescriptor* desc);
  135. // remove?
  136. #define CARLA_NATIVE_PARAMETER_RANGES_INIT { 0.0, 0.0, 1.0, 0.01, 0.0001, 0.1 }
  137. #define CARLA_NATIVE_PLUGIN_INIT { \
  138. PLUGIN_CATEGORY_NONE, 0, NULL, NULL, NULL, NULL, \
  139. 0, NULL, 0, NULL, \
  140. NULL, NULL, NULL, NULL, \
  141. NULL, NULL, NULL, NULL, \
  142. NULL, NULL, NULL, \
  143. NULL, NULL, \
  144. NULL, \
  145. NULL, NULL, NULL \
  146. }
  147. #define CARLA_REGISTER_NATIVE_PLUGIN(label, desc) \
  148. void carla_register_native_plugin_##label () __attribute__((constructor)); \
  149. void carla_register_native_plugin_##label () { carla_register_native_plugin(&desc); }
  150. #ifdef __cplusplus
  151. } /* extern "C" */
  152. #endif
  153. #endif // CARLA_NATIVE_H