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
3.9KB

  1. /*
  2. * Carla JACK API for external applications
  3. * Copyright (C) 2016-2018 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. int jack_set_latency_callback(jack_client_t* client, JackLatencyCallback callback, void* arg)
  21. {
  22. carla_stderr2("%s(%p, %p, %p)", __FUNCTION__, client, callback, arg);
  23. return 0;
  24. }
  25. // --------------------------------------------------------------------------------------------------------------------
  26. CARLA_EXPORT
  27. void jack_port_get_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range)
  28. {
  29. carla_debug("%s(%p, %u, %p)", __FUNCTION__, port, mode, range);
  30. range->min = range->max = 0;
  31. return;
  32. // unused
  33. (void)port;
  34. (void)mode;
  35. }
  36. CARLA_EXPORT
  37. void jack_port_set_latency_range(jack_port_t* port, jack_latency_callback_mode_t mode, jack_latency_range_t* range)
  38. {
  39. carla_stderr2("%s(%p, %u, %p)", __FUNCTION__, port, mode, range);
  40. }
  41. // --------------------------------------------------------------------------------------------------------------------
  42. CARLA_EXPORT
  43. int jack_recompute_total_latencies(jack_client_t* client)
  44. {
  45. carla_stderr2("%s(%p)", __FUNCTION__, client);
  46. return 0;
  47. }
  48. CARLA_EXPORT
  49. jack_nframes_t jack_port_get_latency(jack_port_t* port)
  50. {
  51. carla_debug("%s(%p)", __FUNCTION__, port);
  52. JackPortState* const jport = (JackPortState*)port;
  53. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 0);
  54. if (jport->isMidi || ! jport->isSystem)
  55. return 0;
  56. // TODO
  57. const uint32_t bufferSize = 128;
  58. const uint32_t latencyMultiplier = 3;
  59. if (jport->flags & JackPortIsInput)
  60. return bufferSize*latencyMultiplier;
  61. if (jport->flags & JackPortIsOutput)
  62. return bufferSize;
  63. return 0;
  64. }
  65. CARLA_EXPORT
  66. jack_nframes_t jack_port_get_total_latency(jack_client_t* client, jack_port_t* port)
  67. {
  68. carla_debug("%s(%p, %p)", __FUNCTION__, client, port);
  69. JackClientState* const jclient = (JackClientState*)client;
  70. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 1);
  71. JackPortState* const jport = (JackPortState*)port;
  72. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 0);
  73. if (jport->isMidi)
  74. return 0;
  75. // TODO
  76. const uint32_t bufferSize = jclient->server.bufferSize;
  77. const uint32_t latencyMultiplier = 3;
  78. if (jport->isSystem)
  79. {
  80. if (jport->flags & JackPortIsInput)
  81. return bufferSize*latencyMultiplier;
  82. if (jport->flags & JackPortIsOutput)
  83. return bufferSize;
  84. }
  85. else
  86. {
  87. if (jport->flags & JackPortIsInput)
  88. return bufferSize;
  89. if (jport->flags & JackPortIsOutput)
  90. return bufferSize*latencyMultiplier;
  91. }
  92. return 0;
  93. }
  94. // --------------------------------------------------------------------------------------------------------------------
  95. // deprecated calls
  96. CARLA_EXPORT
  97. void jack_port_set_latency(jack_port_t* port, jack_nframes_t nframes)
  98. {
  99. carla_stderr2("%s(%p, %u)", __FUNCTION__, port, nframes);
  100. }
  101. CARLA_EXPORT
  102. int jack_recompute_total_latency(jack_client_t* client, jack_port_t* port)
  103. {
  104. carla_stderr2("%s(%p, %p)", __FUNCTION__, client, port);
  105. return 0;
  106. }
  107. // --------------------------------------------------------------------------------------------------------------------