Audio plugin host https://kx.studio/carla
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.

176 lines
3.9KB

  1. /*
  2. * Carla Juce Engine
  3. * Copyright (C) 2013 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or 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 GPL.txt file
  16. */
  17. #include "CarlaEngineInternal.hpp"
  18. #include "CarlaBackendUtils.hpp"
  19. #include "CarlaMIDI.h"
  20. #include "RtList.hpp"
  21. #include "JuceHeader.h"
  22. CARLA_BACKEND_START_NAMESPACE
  23. #if 0
  24. } // Fix editor indentation
  25. #endif
  26. // -------------------------------------------------------------------------------------------------------------------
  27. // Juce Engine
  28. static const char** gRetNames = nullptr;
  29. class CarlaEngineJuce : public CarlaEngine,
  30. public AudioIODeviceCallback
  31. {
  32. public:
  33. CarlaEngineJuce()
  34. : CarlaEngine()
  35. {
  36. carla_debug("CarlaEngineJuce::CarlaEngineJuce()");
  37. }
  38. ~CarlaEngineJuce() override
  39. {
  40. if (gRetNames != nullptr)
  41. {
  42. delete[] gRetNames;
  43. gRetNames = nullptr;
  44. }
  45. }
  46. // -------------------------------------
  47. bool init(const char* const clientName) override
  48. {
  49. carla_debug("CarlaEngineJuce::init(\"%s\")", clientName);
  50. CarlaEngine::init(clientName);
  51. return true;
  52. }
  53. bool close() override
  54. {
  55. carla_debug("CarlaEngineJuce::close()");
  56. return CarlaEngine::close();
  57. }
  58. bool isRunning() const override
  59. {
  60. return false;
  61. }
  62. bool isOffline() const override
  63. {
  64. return false;
  65. }
  66. EngineType type() const override
  67. {
  68. return kEngineTypeJuce;
  69. }
  70. // -------------------------------------------------------------------
  71. protected:
  72. void audioDeviceIOCallback (const float** inputChannelData,
  73. int numInputChannels,
  74. float** outputChannelData,
  75. int numOutputChannels,
  76. int numSamples)
  77. {
  78. }
  79. void audioDeviceAboutToStart (AudioIODevice* device)
  80. {
  81. }
  82. void audioDeviceStopped()
  83. {
  84. }
  85. void audioDeviceError (const String& errorMessage)
  86. {
  87. }
  88. // -------------------------------------
  89. private:
  90. AudioIODeviceType* fDeviceType;
  91. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineJuce)
  92. };
  93. // -----------------------------------------
  94. CarlaEngine* CarlaEngine::newJuce()
  95. {
  96. return new CarlaEngineJuce();
  97. }
  98. size_t CarlaEngine::getJuceApiCount()
  99. {
  100. return 0;
  101. }
  102. const char* CarlaEngine::getJuceApiName(const unsigned int index)
  103. {
  104. return nullptr;
  105. }
  106. const char** CarlaEngine::getJuceApiDeviceNames(const unsigned int index)
  107. {
  108. ScopedPointer<AudioIODeviceType*> deviceType;
  109. switch(index)
  110. {
  111. case 0:
  112. deviceType = AudioIODeviceType::createAudioIODeviceType_JACK();
  113. break;
  114. default:
  115. setLastError("");
  116. return nullptr;
  117. }
  118. if (deviceType == nullptr)
  119. {
  120. setLastError("");
  121. return nullptr;
  122. }
  123. deviceType->scanForDevices();
  124. const StringArray devNames(deviceType->getDeviceNames());
  125. const int devNameCount(devNames.size());
  126. if (devNameCount <= 0)
  127. return nullptr;
  128. gRetNames = new const char*[devNameCount+1];
  129. for (unsigned int i=0; i < devNameCount; ++i)
  130. gRetNames[i] = carla_strdup(devNames[i].toRawUTF8());
  131. gRetNames[devNameCount] = nullptr;
  132. return gRetNames;
  133. }
  134. // -----------------------------------------
  135. CARLA_BACKEND_END_NAMESPACE