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.

109 lines
3.9KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Helper functions for extra jacklib functionality
  4. # Copyright (C) 2012 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. errorString = ""
  27. status = cStatus.value
  28. if status & jacklib.JackFailure:
  29. errorString += "Overall operation failed;\n"
  30. if status & jacklib.JackInvalidOption:
  31. errorString += "The operation contained an invalid or unsupported option;\n"
  32. if status & jacklib.JackNameNotUnique:
  33. errorString += "The desired client name was not unique;\n"
  34. if status & jacklib.JackServerStarted:
  35. errorString += "The JACK server was started as a result of this operation;\n"
  36. if status & jacklib.JackServerFailed:
  37. errorString += "Unable to connect to the JACK server;\n"
  38. if status & jacklib.JackServerError:
  39. errorString += "Communication error with the JACK server;\n"
  40. if status & jacklib.JackNoSuchClient:
  41. errorString += "Requested client does not exist;\n"
  42. if status & jacklib.JackLoadFailure:
  43. errorString += "Unable to load internal client;\n"
  44. if status & jacklib.JackInitFailure:
  45. errorString += "Unable to initialize client;\n"
  46. if status & jacklib.JackShmFailure:
  47. errorString += "Unable to access shared memory;\n"
  48. if status & jacklib.JackVersionError:
  49. errorString += "Client's protocol version does not match;\n"
  50. if status & jacklib.JackBackendError:
  51. errorString += "Backend Error;\n"
  52. if status & jacklib.JackClientZombie:
  53. errorString += "Client is being shutdown against its will;\n"
  54. if errorString:
  55. errorString = errorString.strip().rsplit(";", 1)[0] + "."
  56. return errorString
  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* -> jack_default_audio_sample_t*
  75. def translate_audio_port_buffer(void_p):
  76. return jacklib.cast(void_p, jacklib.POINTER(jacklib.jack_default_audio_sample_t))
  77. # ------------------------------------------------------------------------------------------------------------
  78. # Convert a JACK midi buffer into a python variable-size list
  79. def translate_midi_event_buffer(void_p, size):
  80. if not void_p:
  81. return ()
  82. elif size == 1:
  83. return (void_p[0],)
  84. elif size == 2:
  85. return (void_p[0], void_p[1])
  86. elif size == 3:
  87. return (void_p[0], void_p[1], void_p[2])
  88. elif size == 4:
  89. return (void_p[0], void_p[1], void_p[2], void_p[3])
  90. else:
  91. return ()