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.

208 lines
4.6KB

  1. /*
  2. * Carla Backend
  3. * Copyright (C) 2012 Filipe Coelho <falktx@gmail.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_ENGINE_H
  18. #define CARLA_ENGINE_H
  19. #include "carla_backend.h"
  20. #if defined(CARLA_ENGINE_JACK)
  21. #include <jack/jack.h>
  22. #include <jack/midiport.h>
  23. typedef jack_client_t CarlaEngineClientNativeHandle;
  24. struct CarlaEnginePortNativeHandle {
  25. jack_port_t* port;
  26. void* buffer;
  27. };
  28. #elif defined(CARLA_ENGINE_RTAUDIO)
  29. #include "RtAudio.h"
  30. //#include <RtMidi.h>
  31. typedef void* CarlaEngineClientNativeHandle;
  32. typedef void* CarlaEnginePortNativeHandle;
  33. #else
  34. #error Engine type undefined!
  35. #endif
  36. CARLA_BACKEND_START_NAMESPACE
  37. #if 0
  38. } /* adjust editor indent */
  39. #endif
  40. /*!
  41. * @defgroup CarlaBackendEngine Carla Backend Engine
  42. *
  43. * The Carla Backend Engine
  44. * @{
  45. */
  46. const uint32_t CarlaEngineTimeBBT = 0x1;
  47. enum CarlaEnginePortType {
  48. CarlaEnginePortTypeAudio,
  49. CarlaEnginePortTypeControl,
  50. CarlaEnginePortTypeMIDI
  51. };
  52. enum CarlaEngineControlEventType {
  53. CarlaEngineEventControlChange,
  54. CarlaEngineEventMidiBankChange,
  55. CarlaEngineEventMidiProgramChange,
  56. CarlaEngineEventAllSoundOff,
  57. CarlaEngineEventAllNotesOff
  58. };
  59. struct CarlaEngineControlEvent {
  60. CarlaEngineControlEventType type;
  61. uint32_t time;
  62. uint8_t channel;
  63. uint8_t controller;
  64. double value;
  65. };
  66. struct CarlaEngineMidiEvent {
  67. uint32_t time;
  68. uint8_t size;
  69. uint8_t data[4];
  70. };
  71. struct CarlaTimeInfo {
  72. bool playing;
  73. uint32_t frame;
  74. uint32_t time;
  75. uint32_t valid;
  76. struct {
  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. } bbt;
  86. };
  87. // -----------------------------------------
  88. class CarlaEngine
  89. {
  90. public:
  91. CarlaEngine();
  92. ~CarlaEngine();
  93. static bool init(const char* name);
  94. static bool close();
  95. static bool isOnAudioThread();
  96. static bool isOffline();
  97. static int maxClientNameSize();
  98. static int maxPortNameSize();
  99. static const CarlaTimeInfo* getTimeInfo();
  100. };
  101. // -----------------------------------------
  102. class CarlaEngineBasePort
  103. {
  104. public:
  105. CarlaEngineBasePort(CarlaEngineClientNativeHandle* const client, bool isInput);
  106. virtual ~CarlaEngineBasePort();
  107. virtual void initBuffer() = 0;
  108. protected:
  109. const bool isInput;
  110. CarlaEnginePortNativeHandle handle;
  111. CarlaEngineClientNativeHandle* const client;
  112. };
  113. // -----------------------------------------
  114. class CarlaEngineClient
  115. {
  116. public:
  117. CarlaEngineClient(CarlaPlugin* const plugin);
  118. ~CarlaEngineClient();
  119. void activate();
  120. void deactivate();
  121. bool isActive();
  122. bool isOk();
  123. CarlaEngineBasePort* addPort(const char* name, CarlaEnginePortType type, bool isInput);
  124. private:
  125. CarlaEngineClientNativeHandle* handle;
  126. bool m_active;
  127. };
  128. // -----------------------------------------
  129. class CarlaEngineAudioPort : public CarlaEngineBasePort
  130. {
  131. public:
  132. CarlaEngineAudioPort(CarlaEngineClientNativeHandle* const client, const char* name, bool isInput);
  133. void initBuffer();
  134. #ifdef CARLA_ENGINE_JACK
  135. float* getJackAudioBuffer();
  136. #endif
  137. };
  138. // -----------------------------------------
  139. class CarlaEngineControlPort : public CarlaEngineBasePort
  140. {
  141. public:
  142. CarlaEngineControlPort(CarlaEngineClientNativeHandle* const client, const char* name, bool isInput);
  143. void initBuffer();
  144. uint32_t getEventCount();
  145. const CarlaEngineControlEvent* getEvent(uint32_t index);
  146. void writeEvent(CarlaEngineControlEventType type, uint32_t time, uint8_t channel, uint8_t controller, double value);
  147. };
  148. // -----------------------------------------
  149. class CarlaEngineMidiPort : public CarlaEngineBasePort
  150. {
  151. public:
  152. CarlaEngineMidiPort(CarlaEngineClientNativeHandle* const client, const char* name, bool isInput);
  153. void initBuffer();
  154. uint32_t getEventCount();
  155. const CarlaEngineMidiEvent* getEvent(uint32_t index);
  156. void writeEvent(uint32_t time, uint8_t* data, uint8_t size);
  157. };
  158. /**@}*/
  159. CARLA_BACKEND_END_NAMESPACE
  160. #endif // CARLA_ENGINE_H