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.

118 lines
4.1KB

  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. errorString = ""
  30. if status & jacklib.JackFailure:
  31. errorString += "Overall operation failed;\n"
  32. if status & jacklib.JackInvalidOption:
  33. errorString += "The operation contained an invalid or unsupported option;\n"
  34. if status & jacklib.JackNameNotUnique:
  35. errorString += "The desired client name was not unique;\n"
  36. if status & jacklib.JackServerStarted:
  37. errorString += "The JACK server was started as a result of this operation;\n"
  38. if status & jacklib.JackServerFailed:
  39. errorString += "Unable to connect to the JACK server;\n"
  40. if status & jacklib.JackServerError:
  41. errorString += "Communication error with the JACK server;\n"
  42. if status & jacklib.JackNoSuchClient:
  43. errorString += "Requested client does not exist;\n"
  44. if status & jacklib.JackLoadFailure:
  45. errorString += "Unable to load internal client;\n"
  46. if status & jacklib.JackInitFailure:
  47. errorString += "Unable to initialize client;\n"
  48. if status & jacklib.JackShmFailure:
  49. errorString += "Unable to access shared memory;\n"
  50. if status & jacklib.JackVersionError:
  51. errorString += "Client's protocol version does not match;\n"
  52. if status & jacklib.JackBackendError:
  53. errorString += "Backend Error;\n"
  54. if status & jacklib.JackClientZombie:
  55. errorString += "Client is being shutdown against its will;\n"
  56. return errorString.strip().rsplit(";", 1)[0] + "."
  57. # ------------------------------------------------------------------------------------------------------------
  58. # Convert C char** -> Python list
  59. def c_char_p_p_to_list(c_char_p_p):
  60. i = 0
  61. retList = []
  62. if not c_char_p_p:
  63. return retList
  64. while True:
  65. new_char_p = c_char_p_p[i]
  66. if new_char_p:
  67. retList.append(str(new_char_p, encoding="utf-8"))
  68. i += 1
  69. else:
  70. break
  71. jacklib.free(c_char_p_p)
  72. return retList
  73. # ------------------------------------------------------------------------------------------------------------
  74. # Convert C void* -> string
  75. def voidptr2str(void_p):
  76. char_p = jacklib.cast(void_p, jacklib.c_char_p)
  77. string = str(char_p.value, encoding="utf-8")
  78. return string
  79. # ------------------------------------------------------------------------------------------------------------
  80. # Convert C void* -> jack_default_audio_sample_t*
  81. def translate_audio_port_buffer(void_p):
  82. return jacklib.cast(void_p, jacklib.POINTER(jacklib.jack_default_audio_sample_t))
  83. # ------------------------------------------------------------------------------------------------------------
  84. # Convert a JACK midi buffer into a python variable-size list
  85. def translate_midi_event_buffer(void_p, size):
  86. if not void_p:
  87. return ()
  88. elif size == 1:
  89. return (void_p[0],)
  90. elif size == 2:
  91. return (void_p[0], void_p[1])
  92. elif size == 3:
  93. return (void_p[0], void_p[1], void_p[2])
  94. elif size == 4:
  95. return (void_p[0], void_p[1], void_p[2], void_p[3])
  96. else:
  97. return ()