Collection of tools useful for audio production
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.

110 lines
3.8KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Helper functions for extra jacklib functionality
  4. # Copyright (C) 2012-2013 Filipe Coelho <falktx@falktx.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # For a full copy of the GNU General Public License see the COPYING file
  17. # ------------------------------------------------------------------------------------------------------------
  18. # Try Import jacklib
  19. try:
  20. import jacklib
  21. except ImportError:
  22. jacklib = None
  23. # ------------------------------------------------------------------------------------------------------------
  24. # Get JACK error status as string
  25. def get_jack_status_error_string(cStatus):
  26. status = cStatus.value
  27. if status == 0x0:
  28. return ""
  29. errors_map = [
  30. (jacklib.JackFailure, "Overall operation failed"),
  31. (jacklib.JackInvalidOption, "The operation contained an invalid or unsupported option"),
  32. (jacklib.JackNameNotUnique, "The desired client name was not unique"),
  33. (jacklib.JackServerStarted, "The JACK server was started as a result of this operation"),
  34. (jacklib.JackServerFailed, "Unable to connect to the JACK server"),
  35. (jacklib.JackServerError, "Communication error with the JACK server"),
  36. (jacklib.JackNoSuchClient, "Requested client does not exist"),
  37. (jacklib.JackLoadFailure, "Unable to load internal client"),
  38. (jacklib.JackInitFailure, "Unable to initialize client"),
  39. (jacklib.JackShmFailure, "Unable to access shared memory"),
  40. (jacklib.JackVersionError, "Client's protocol version does not match"),
  41. (jacklib.JackBackendError, "Backend Error"),
  42. (jacklib.JackClientZombie, "Client is being shutdown against its will"),
  43. ]
  44. errors_list = [
  45. error_line for error, error_line in errors_map
  46. if status & error
  47. ]
  48. return ';\n'.join(errors_list) + '.'
  49. # ------------------------------------------------------------------------------------------------------------
  50. # Convert C char** -> Python list
  51. def c_char_p_p_to_list(c_char_p_p):
  52. i = 0
  53. retList = []
  54. if not c_char_p_p:
  55. return retList
  56. while True:
  57. new_char_p = c_char_p_p[i]
  58. if new_char_p:
  59. retList.append(str(new_char_p, encoding="utf-8"))
  60. i += 1
  61. else:
  62. break
  63. jacklib.free(c_char_p_p)
  64. return retList
  65. # ------------------------------------------------------------------------------------------------------------
  66. # Convert C void* -> string
  67. def voidptr2str(void_p):
  68. char_p = jacklib.cast(void_p, jacklib.c_char_p)
  69. string = str(char_p.value, encoding="utf-8")
  70. return string
  71. # ------------------------------------------------------------------------------------------------------------
  72. # Convert C void* -> jack_default_audio_sample_t*
  73. def translate_audio_port_buffer(void_p):
  74. return jacklib.cast(void_p, jacklib.POINTER(jacklib.jack_default_audio_sample_t))
  75. # ------------------------------------------------------------------------------------------------------------
  76. # Convert a JACK midi buffer into a python variable-size list
  77. def translate_midi_event_buffer(void_p, size):
  78. if not void_p:
  79. return ()
  80. elif size == 1:
  81. return (void_p[0],)
  82. elif size == 2:
  83. return (void_p[0], void_p[1])
  84. elif size == 3:
  85. return (void_p[0], void_p[1], void_p[2])
  86. elif size == 4:
  87. return (void_p[0], void_p[1], void_p[2], void_p[3])
  88. else:
  89. return ()