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.

137 lines
4.4KB

  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* client, const char* a, const char* b, unsigned long flags)
  23. {
  24. carla_stdout("%s(%p, %s, %s, 0x%lx) WIP", __FUNCTION__, client, a, b, flags);
  25. JackClientState* const jclient = (JackClientState*)client;
  26. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, nullptr);
  27. static const char* capture_1 = "system:capture_1";
  28. static const char* capture_2 = "system:capture_2";
  29. static const char* playback_1 = "system:playback_1";
  30. static const char* playback_2 = "system:playback_2";
  31. if (flags == 0 || (flags & (JackPortIsInput|JackPortIsOutput)) == (JackPortIsInput|JackPortIsOutput))
  32. {
  33. if (const char** const ret = (const char**)calloc(5, sizeof(const char*)))
  34. {
  35. ret[0] = capture_1;
  36. ret[1] = capture_2;
  37. ret[2] = playback_1;
  38. ret[3] = playback_2;
  39. ret[4] = nullptr;
  40. return ret;
  41. }
  42. }
  43. if (flags & JackPortIsInput)
  44. {
  45. if (const char** const ret = (const char**)calloc(3, sizeof(const char*)))
  46. {
  47. ret[0] = playback_1;
  48. ret[1] = playback_2;
  49. ret[2] = nullptr;
  50. return ret;
  51. }
  52. }
  53. if (flags & JackPortIsOutput)
  54. {
  55. if (const char** const ret = (const char**)calloc(3, sizeof(const char*)))
  56. {
  57. ret[0] = capture_1;
  58. ret[1] = capture_2;
  59. ret[2] = nullptr;
  60. return ret;
  61. }
  62. }
  63. return nullptr;
  64. }
  65. CARLA_EXPORT
  66. jack_port_t* jack_port_by_name(jack_client_t* client, const char* name)
  67. {
  68. carla_stdout("%s(%p, %s) WIP", __FUNCTION__, client, name);
  69. JackClientState* const jclient = (JackClientState*)client;
  70. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 0);
  71. const JackServerState& jserver(jclient->server);
  72. const int commonFlags = JackPortIsPhysical|JackPortIsTerminal;
  73. static const JackPortState capturePorts[] = {
  74. JackPortState("system", "capture_1", 0, JackPortIsOutput|commonFlags, false, true, jserver.numAudioIns > 0),
  75. JackPortState("system", "capture_2", 1, JackPortIsOutput|commonFlags, false, true, jserver.numAudioIns > 1),
  76. };
  77. static const JackPortState playbackPorts[] = {
  78. JackPortState("system", "playback_1", 3, JackPortIsInput|commonFlags, false, true, jserver.numAudioOuts > 0),
  79. JackPortState("system", "playback_2", 4, JackPortIsInput|commonFlags, false, true, jserver.numAudioOuts > 1),
  80. };
  81. if (std::strncmp(name, "system:", 7) == 0)
  82. {
  83. name += 7;
  84. /**/ if (std::strncmp(name, "capture_", 8) == 0)
  85. {
  86. name += 8;
  87. const int index = std::atoi(name)-1;
  88. CARLA_SAFE_ASSERT_RETURN(index >= 0 && index < 2, nullptr);
  89. return (jack_port_t*)&capturePorts[index];
  90. }
  91. else if (std::strncmp(name, "playback_", 9) == 0)
  92. {
  93. name += 9;
  94. const int index = std::atoi(name)-1;
  95. CARLA_SAFE_ASSERT_RETURN(index >= 0, nullptr);
  96. return (jack_port_t*)&playbackPorts[index];
  97. }
  98. else
  99. {
  100. carla_stderr2("jack_port_by_name: invalid port short name '%s'", name);
  101. return nullptr;
  102. }
  103. }
  104. carla_stderr2("jack_port_by_name: invalid port name '%s'", name);
  105. return nullptr;
  106. }
  107. CARLA_EXPORT
  108. jack_port_t* jack_port_by_id(jack_client_t* client, jack_port_id_t port_id)
  109. {
  110. carla_stderr2("%s(%p, %u)", __FUNCTION__, client, port_id);
  111. return nullptr;
  112. }
  113. // --------------------------------------------------------------------------------------------------------------------