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.

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