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.

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