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.

94 lines
3.2KB

  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # Helper functions for extra jacklib functionality
  4. # Copyright (C) 2012 Filipe Coelho <falktx@gmail.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. import jacklib
  18. def get_jack_status_error_string(c_status):
  19. status = c_status.value
  20. error_string = ""
  21. if status & jacklib.JackFailure:
  22. error_string += "Overall operation failed;\n"
  23. if status & jacklib.JackInvalidOption:
  24. error_string += "The operation contained an invalid or unsupported option;\n"
  25. if status & jacklib.JackNameNotUnique:
  26. error_string += "The desired client name was not unique;\n"
  27. if status & jacklib.JackServerStarted:
  28. error_string += "The JACK server was started as a result of this operation;\n"
  29. if status & jacklib.JackServerFailed:
  30. error_string += "Unable to connect to the JACK server;\n"
  31. if status & jacklib.JackServerError:
  32. error_string += "Communication error with the JACK server;\n"
  33. if status & jacklib.JackNoSuchClient:
  34. error_string += "Requested client does not exist;\n"
  35. if status & jacklib.JackLoadFailure:
  36. error_string += "Unable to load internal client;\n"
  37. if status & jacklib.JackInitFailure:
  38. error_string += "Unable to initialize client;\n"
  39. if status & jacklib.JackShmFailure:
  40. error_string += "Unable to access shared memory;\n"
  41. if status & jacklib.JackVersionError:
  42. error_string += "Client's protocol version does not match;\n"
  43. if status & jacklib.JackBackendError:
  44. error_string += "Backend Error;\n"
  45. if status & jacklib.JackClientZombie:
  46. error_string += "Client is being shutdown against its will;\n"
  47. if error_string:
  48. error_string = error_string.strip().rsplit(";", 1)[0] + "."
  49. return error_string
  50. # C char** -> Python list conversion
  51. def c_char_p_p_to_list(c_char_p_p):
  52. i = 0
  53. final_list = []
  54. if not c_char_p_p:
  55. return final_list
  56. while True:
  57. new_char_p = c_char_p_p[i]
  58. if new_char_p:
  59. final_list.append(str(new_char_p, encoding="utf-8"))
  60. i += 1
  61. else:
  62. break
  63. jacklib.free(c_char_p_p)
  64. return final_list
  65. # C cast void* -> jack_default_audio_sample_t*
  66. def translate_audio_port_buffer(void_p):
  67. return jacklib.cast(void_p, jacklib.POINTER(jacklib.jack_default_audio_sample_t))
  68. # Convert a jack midi buffer into a variable-size list
  69. def translate_midi_event_buffer(void_p, size):
  70. if not void_p:
  71. return ()
  72. elif size == 1:
  73. return (void_p[0],)
  74. elif size == 2:
  75. return (void_p[0], void_p[1])
  76. elif size == 3:
  77. return (void_p[0], void_p[1], void_p[2])
  78. elif size == 4:
  79. return (void_p[0], void_p[1], void_p[2], void_p[3])
  80. else:
  81. return ()