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.

CarlaEngineClient.cpp 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2014 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 doc/GPL.txt file.
  16. */
  17. #include "CarlaEngineUtils.hpp"
  18. #include "CarlaStringList.hpp"
  19. CARLA_BACKEND_START_NAMESPACE
  20. // -----------------------------------------------------------------------
  21. // Carla Engine client (Abstract)
  22. struct CarlaEngineClient::ProtectedData {
  23. const CarlaEngine& engine;
  24. bool active;
  25. uint32_t latency;
  26. CarlaStringList audioInList;
  27. CarlaStringList audioOutList;
  28. ProtectedData(const CarlaEngine& eng)
  29. : engine(eng),
  30. active(false),
  31. latency(0),
  32. audioInList(),
  33. audioOutList() {}
  34. #ifdef CARLA_PROPER_CPP11_SUPPORT
  35. ProtectedData() = delete;
  36. CARLA_DECLARE_NON_COPY_STRUCT(ProtectedData)
  37. #endif
  38. };
  39. CarlaEngineClient::CarlaEngineClient(const CarlaEngine& engine)
  40. : pData(new ProtectedData(engine))
  41. {
  42. carla_debug("CarlaEngineClient::CarlaEngineClient()");
  43. }
  44. CarlaEngineClient::~CarlaEngineClient() noexcept
  45. {
  46. CARLA_SAFE_ASSERT(! pData->active);
  47. carla_debug("CarlaEngineClient::~CarlaEngineClient()");
  48. delete pData;
  49. }
  50. void CarlaEngineClient::activate() noexcept
  51. {
  52. CARLA_SAFE_ASSERT(! pData->active);
  53. carla_debug("CarlaEngineClient::activate()");
  54. pData->active = true;
  55. }
  56. void CarlaEngineClient::deactivate() noexcept
  57. {
  58. CARLA_SAFE_ASSERT(pData->active);
  59. carla_debug("CarlaEngineClient::deactivate()");
  60. pData->active = false;
  61. }
  62. bool CarlaEngineClient::isActive() const noexcept
  63. {
  64. return pData->active;
  65. }
  66. bool CarlaEngineClient::isOk() const noexcept
  67. {
  68. return true;
  69. }
  70. uint32_t CarlaEngineClient::getLatency() const noexcept
  71. {
  72. return pData->latency;
  73. }
  74. void CarlaEngineClient::setLatency(const uint32_t samples) noexcept
  75. {
  76. pData->latency = samples;
  77. }
  78. CarlaEnginePort* CarlaEngineClient::addPort(const EnginePortType portType, const char* const name, const bool isInput)
  79. {
  80. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0', nullptr);
  81. carla_debug("CarlaEngineClient::addPort(%i:%s, \"%s\", %s)", portType, EnginePortType2Str(portType), name, bool2str(isInput));
  82. _addName(isInput, name);
  83. switch (portType)
  84. {
  85. case kEnginePortTypeNull:
  86. break;
  87. case kEnginePortTypeAudio:
  88. return new CarlaEngineAudioPort(*this, isInput);
  89. case kEnginePortTypeCV:
  90. return new CarlaEngineCVPort(*this, isInput);
  91. case kEnginePortTypeEvent:
  92. return new CarlaEngineEventPort(*this, isInput);
  93. }
  94. carla_stderr("CarlaEngineClient::addPort(%i, \"%s\", %s) - invalid type", portType, name, bool2str(isInput));
  95. return nullptr;
  96. }
  97. const CarlaEngine& CarlaEngineClient::getEngine() const noexcept
  98. {
  99. return pData->engine;
  100. }
  101. EngineProcessMode CarlaEngineClient::getProcessMode() const noexcept
  102. {
  103. return pData->engine.getProccessMode();
  104. }
  105. const char* CarlaEngineClient::getAudioInputPortName(const uint index) const noexcept
  106. {
  107. CARLA_SAFE_ASSERT_RETURN(index < pData->audioInList.count(), nullptr);
  108. return pData->audioInList.getAt(index, nullptr);
  109. }
  110. const char* CarlaEngineClient::getAudioOutputPortName(const uint index) const noexcept
  111. {
  112. CARLA_SAFE_ASSERT_RETURN(index < pData->audioOutList.count(), nullptr);
  113. return pData->audioOutList.getAt(index, nullptr);
  114. }
  115. void CarlaEngineClient::_addName(const bool isInput, const char* const name)
  116. {
  117. CARLA_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',);
  118. if (isInput)
  119. pData->audioInList.append(name);
  120. else
  121. pData->audioOutList.append(name);
  122. }
  123. // -----------------------------------------------------------------------
  124. CARLA_BACKEND_END_NAMESPACE