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.

89 lines
2.9KB

  1. /*
  2. * Common JACK code
  3. * Copyright (C) 2012 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING file
  16. */
  17. #ifndef __JACK_UTILS_HPP__
  18. #define __JACK_UTILS_HPP__
  19. #include <jack/jack.h>
  20. #include <jack/midiport.h>
  21. #include <jack/transport.h>
  22. #ifdef HAVE_JACKSESSION
  23. # include <jack/session.h>
  24. #endif
  25. #include <cstring>
  26. #include <string>
  27. #include <vector>
  28. static inline
  29. std::vector<char*> jack_port_get_all_connections_as_vector(jack_client_t* const client, jack_port_t* const port)
  30. {
  31. std::vector<char*> connectionsVector;
  32. const char** connections = jack_port_get_all_connections(client, port);
  33. if (connections)
  34. {
  35. for (int i=0; connections[i]; i++)
  36. connectionsVector.push_back(strdup(connections[i]));
  37. jack_free(connections);
  38. }
  39. return connectionsVector;
  40. }
  41. static inline
  42. std::string jack_status_get_error_string(const jack_status_t& status)
  43. {
  44. std::string errorString;
  45. if (status & JackFailure)
  46. errorString += "Overall operation failed;\n";
  47. if (status & JackInvalidOption)
  48. errorString += "The operation contained an invalid or unsupported option;\n";
  49. if (status & JackNameNotUnique)
  50. errorString += "The desired client name was not unique;\n";
  51. if (status & JackServerStarted)
  52. errorString += "The JACK server was started as a result of this operation;\n";
  53. if (status & JackServerFailed)
  54. errorString += "Unable to connect to the JACK server;\n";
  55. if (status & JackServerError)
  56. errorString += "Communication error with the JACK server;\n";
  57. if (status & JackNoSuchClient)
  58. errorString += "Requested client does not exist;\n";
  59. if (status & JackLoadFailure)
  60. errorString += "Unable to load internal client;\n";
  61. if (status & JackInitFailure)
  62. errorString += "Unable to initialize client;\n";
  63. if (status & JackShmFailure)
  64. errorString += "Unable to access shared memory;\n";
  65. if (status & JackVersionError)
  66. errorString += "Client's protocol version does not match;\n";
  67. if (status & JackBackendError)
  68. errorString += "Backend Error;\n";
  69. if (status & JackClientZombie)
  70. errorString += "Client is being shutdown against its will;\n";
  71. if (errorString.size() > 2)
  72. errorString.replace(errorString.size()-2, 2, ".");
  73. return errorString;
  74. }
  75. #endif // __JACK_UTILS_HPP__