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.

113 lines
3.6KB

  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. 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. //void jack_port_set_latency (jack_port_t *port, jack_nframes_t) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  27. // --------------------------------------------------------------------------------------------------------------------
  28. CARLA_EXPORT
  29. void jack_port_get_latency_range(jack_port_t*, jack_latency_callback_mode_t, jack_latency_range_t* range)
  30. {
  31. range->min = range->max = 0;
  32. }
  33. //void jack_port_set_latency_range (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range) JACK_WEAK_EXPORT;
  34. // --------------------------------------------------------------------------------------------------------------------
  35. CARLA_EXPORT
  36. int jack_recompute_total_latencies(jack_client_t* client)
  37. {
  38. carla_stderr2("%s(%p)", __FUNCTION__, client);
  39. return 0;
  40. }
  41. CARLA_EXPORT
  42. jack_nframes_t jack_port_get_latency(jack_port_t* port)
  43. {
  44. JackPortState* const jport = (JackPortState*)port;
  45. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 0);
  46. if (jport->isMidi || ! jport->isSystem)
  47. return 0;
  48. // TODO
  49. const uint32_t bufferSize = 128;
  50. const uint32_t latencyMultiplier = 3;
  51. if (jport->flags & JackPortIsInput)
  52. return bufferSize*latencyMultiplier;
  53. if (jport->flags & JackPortIsOutput)
  54. return bufferSize;
  55. return 0;
  56. }
  57. CARLA_EXPORT
  58. jack_nframes_t jack_port_get_total_latency(jack_client_t* client, jack_port_t* port)
  59. {
  60. JackClientState* const jclient = (JackClientState*)client;
  61. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 1);
  62. JackPortState* const jport = (JackPortState*)port;
  63. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 0);
  64. if (jport->isMidi)
  65. return 0;
  66. // TODO
  67. const uint32_t bufferSize = jclient->server.bufferSize;
  68. const uint32_t latencyMultiplier = 3;
  69. if (jport->isSystem)
  70. {
  71. if (jport->flags & JackPortIsInput)
  72. return bufferSize*latencyMultiplier;
  73. if (jport->flags & JackPortIsOutput)
  74. return bufferSize;
  75. }
  76. else
  77. {
  78. if (jport->flags & JackPortIsInput)
  79. return bufferSize;
  80. if (jport->flags & JackPortIsOutput)
  81. return bufferSize*latencyMultiplier;
  82. }
  83. return 0;
  84. }
  85. // --------------------------------------------------------------------------------------------------------------------
  86. //int jack_recompute_total_latency (jack_client_t*, jack_port_t* port) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  87. // --------------------------------------------------------------------------------------------------------------------