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.

180 lines
5.5KB

  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 _HostDescriptor {
  92. uint32_t (*get_buffer_size)();
  93. double (*get_sample_rate)();
  94. const TimeInfo* (*get_time_info)();
  95. bool (*write_midi_event)(uint32_t port_offset, MidiEvent* event);
  96. } HostDescriptor;
  97. typedef struct _PluginPortScalePoint {
  98. const char* label;
  99. double value;
  100. } PluginPortScalePoint;
  101. typedef struct _PluginPort {
  102. PortType type;
  103. uint32_t hints;
  104. const char* name;
  105. uint32_t scalePointCount;
  106. PluginPortScalePoint* scalePoints;
  107. } PluginPort;
  108. typedef struct _PluginDescriptor {
  109. PluginCategory category;
  110. uint32_t hints;
  111. const char* name;
  112. const char* label;
  113. const char* maker;
  114. const char* copyright;
  115. uint32_t portCount;
  116. PluginPort* ports;
  117. uint32_t midiProgramCount;
  118. MidiProgram* midiPrograms;
  119. PluginHandle (*instantiate)(struct _PluginDescriptor* _this_, HostDescriptor* host);
  120. void (*activate)(PluginHandle handle);
  121. void (*deactivate)(PluginHandle handle);
  122. void (*cleanup)(PluginHandle handle);
  123. void (*get_parameter_ranges)(PluginHandle handle, uint32_t index, ParameterRanges* ranges);
  124. double (*get_parameter_value)(PluginHandle handle, uint32_t index);
  125. const char* (*get_parameter_text)(PluginHandle handle, uint32_t index);
  126. const char* (*get_parameter_unit)(PluginHandle handle, uint32_t index);
  127. void (*set_parameter_value)(PluginHandle handle, uint32_t index, double value);
  128. void (*set_midi_program)(PluginHandle handle, uint32_t bank, uint32_t program);
  129. void (*set_custom_data)(PluginHandle handle, const char* key, const char* value);
  130. void (*show_gui)(PluginHandle handle, bool show);
  131. void (*idle_gui)(PluginHandle handle);
  132. // TODO - ui_set_*
  133. void (*process)(PluginHandle handle, float** inBuffer, float** outBuffer, uint32_t frames, uint32_t midiEventCount, MidiEvent* midiEvents);
  134. // TODO - midi stuff^
  135. void* _singleton;
  136. void (*_init)(struct _PluginDescriptor* _this_);
  137. void (*_fini)(struct _PluginDescriptor* _this_);
  138. } PluginDescriptor;
  139. // -----------------------------------------------------------------------
  140. void carla_register_native_plugin(const PluginDescriptor* desc);
  141. #define CARLA_REGISTER_NATIVE_PLUGIN(label, desc) \
  142. void carla_register_native_plugin_##label () __attribute__((constructor)); \
  143. void carla_register_native_plugin_##label () { carla_register_native_plugin(&desc); }
  144. #ifdef __cplusplus
  145. } /* extern "C" */
  146. #endif
  147. #endif // CARLA_NATIVE_H