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.

135 lines
4.2KB

  1. /*
  2. * Carla JACK API for external applications
  3. * Copyright (C) 2016-2017 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. // need to include this first
  18. #include "libjack.hpp"
  19. CARLA_BACKEND_USE_NAMESPACE
  20. // --------------------------------------------------------------------------------------------------------------------
  21. CARLA_EXPORT
  22. const char** jack_get_ports(jack_client_t*, const char* a, const char* b, unsigned long flags)
  23. {
  24. carla_stdout("CarlaJackClient :: %s | %s %s %li", __FUNCTION__, a, b, flags);
  25. static const char* capture_1 = "system:capture_1";
  26. static const char* capture_2 = "system:capture_2";
  27. static const char* playback_1 = "system:playback_1";
  28. static const char* playback_2 = "system:playback_2";
  29. if (flags == 0 || (flags & (JackPortIsInput|JackPortIsOutput)) == (JackPortIsInput|JackPortIsOutput))
  30. {
  31. if (const char** const ret = (const char**)calloc(5, sizeof(const char*)))
  32. {
  33. ret[0] = capture_1;
  34. ret[1] = capture_2;
  35. ret[2] = playback_1;
  36. ret[3] = playback_2;
  37. ret[4] = nullptr;
  38. return ret;
  39. }
  40. }
  41. if (flags & JackPortIsInput)
  42. {
  43. if (const char** const ret = (const char**)calloc(3, sizeof(const char*)))
  44. {
  45. ret[0] = playback_1;
  46. ret[1] = playback_2;
  47. ret[2] = nullptr;
  48. return ret;
  49. }
  50. }
  51. if (flags & JackPortIsOutput)
  52. {
  53. if (const char** const ret = (const char**)calloc(3, sizeof(const char*)))
  54. {
  55. ret[0] = capture_1;
  56. ret[1] = capture_2;
  57. ret[2] = nullptr;
  58. return ret;
  59. }
  60. }
  61. return nullptr;
  62. }
  63. CARLA_EXPORT
  64. jack_port_t* jack_port_by_name(jack_client_t* /*client*/, const char* name)
  65. {
  66. carla_stdout("CarlaJackClient :: %s | %s", __FUNCTION__, name);
  67. // CarlaJackClient* const jclient = (CarlaJackClient*)client;
  68. // CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 0);
  69. // const JackClientState& jstate(jclient->fState);
  70. //CARLA_SAFE_ASSERT_RETURN(jstate.activated, 0);
  71. static const JackPortState capturePorts[] = {
  72. JackPortState("system", "capture_1", 0, JackPortIsOutput|JackPortIsPhysical|JackPortIsTerminal, true),
  73. JackPortState("system", "capture_2", 1, JackPortIsOutput|JackPortIsPhysical|JackPortIsTerminal, true),
  74. };
  75. static const JackPortState playbackPorts[] = {
  76. JackPortState("system", "playback_1", 3, JackPortIsInput|JackPortIsPhysical|JackPortIsTerminal, true),
  77. JackPortState("system", "playback_2", 4, JackPortIsInput|JackPortIsPhysical|JackPortIsTerminal, true),
  78. };
  79. if (std::strncmp(name, "system:", 7) == 0)
  80. {
  81. name += 7;
  82. /**/ if (std::strncmp(name, "capture_", 8) == 0)
  83. {
  84. name += 8;
  85. const int index = std::atoi(name);
  86. CARLA_SAFE_ASSERT_RETURN(index >= 0 && index < 2, nullptr);
  87. return (jack_port_t*)&capturePorts[index];
  88. }
  89. else if (std::strncmp(name, "playback_", 9) == 0)
  90. {
  91. name += 9;
  92. const int index = std::atoi(name);
  93. CARLA_SAFE_ASSERT_RETURN(index >= 0, nullptr);
  94. return (jack_port_t*)&playbackPorts[index];
  95. }
  96. else
  97. {
  98. carla_stderr2("Invalid port short name: '%s'", name);
  99. return nullptr;
  100. }
  101. }
  102. carla_stderr2("Invalid port name: '%s'", name);
  103. return nullptr;
  104. }
  105. CARLA_EXPORT
  106. jack_port_t* jack_port_by_id(jack_client_t*, jack_port_id_t)
  107. {
  108. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  109. return nullptr;
  110. }
  111. // --------------------------------------------------------------------------------------------------------------------