JACK tools
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.

132 lines
3.6KB

  1. /*
  2. Copyright (C) 2007 Paul Davis
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #include <stdio.h>
  16. #include <errno.h>
  17. #include <unistd.h>
  18. #include <string.h>
  19. #include <stdlib.h>
  20. #include <jack/jack.h>
  21. #include <jack/metadata.h>
  22. #include <jack/uuid.h>
  23. void
  24. port_callback (jack_port_id_t port, int yn, void* arg)
  25. {
  26. printf ("Port %d %s\n", port, (yn ? "registered" : "unregistered"));
  27. }
  28. void
  29. connect_callback (jack_port_id_t a, jack_port_id_t b, int yn, void* arg)
  30. {
  31. printf ("Ports %d and %d %s\n", a, b, (yn ? "connected" : "disconnected"));
  32. }
  33. void
  34. client_callback (const char* client, int yn, void* arg)
  35. {
  36. printf ("Client %s %s\n", client, (yn ? "registered" : "unregistered"));
  37. }
  38. int
  39. graph_callback (void* arg)
  40. {
  41. printf ("Graph reordered\n");
  42. return 0;
  43. }
  44. void
  45. propchange (jack_uuid_t subject, const char* key, jack_property_change_t change)
  46. {
  47. char buf[JACK_UUID_STRING_SIZE];
  48. const char* action = "";
  49. switch (change) {
  50. case PropertyCreated:
  51. action = "created";
  52. break;
  53. case PropertyChanged:
  54. action = "changed";
  55. break;
  56. case PropertyDeleted:
  57. action = "deleted";
  58. break;
  59. }
  60. if (jack_uuid_empty (subject)) {
  61. printf ("All properties changed!\n");
  62. } else {
  63. jack_uuid_unparse (subject, buf);
  64. if (key) {
  65. printf ("key [%s] for %s %s\n", key, buf, action);
  66. } else {
  67. printf ("all keys for %s %s\n", buf, action);
  68. }
  69. }
  70. }
  71. int
  72. main (int argc, char *argv[])
  73. {
  74. jack_client_t *client;
  75. jack_options_t options = JackNullOption;
  76. jack_status_t status;
  77. if ((client = jack_client_open ("event-monitor", options, &status, NULL)) == 0) {
  78. fprintf (stderr, "jack_client_open() failed, "
  79. "status = 0x%2.0x\n", status);
  80. if (status & JackServerFailed) {
  81. fprintf (stderr, "Unable to connect to JACK server\n");
  82. }
  83. return 1;
  84. }
  85. if (jack_set_port_registration_callback (client, port_callback, NULL)) {
  86. fprintf (stderr, "cannot set port registration callback\n");
  87. return 1;
  88. }
  89. if (jack_set_port_connect_callback (client, connect_callback, NULL)) {
  90. fprintf (stderr, "cannot set port connect callback\n");
  91. return 1;
  92. }
  93. if (jack_set_client_registration_callback (client, client_callback, NULL)) {
  94. fprintf (stderr, "cannot set client registration callback\n");
  95. return 1;
  96. }
  97. if (jack_set_graph_order_callback (client, graph_callback, NULL)) {
  98. fprintf (stderr, "cannot set graph order registration callback\n");
  99. return 1;
  100. }
  101. if (jack_set_property_change_callback (client, (JackPropertyChangeCallback) propchange, 0)) {
  102. fprintf (stderr, "cannot set property change callback\n");
  103. return 1;
  104. }
  105. if (jack_activate (client)) {
  106. fprintf (stderr, "cannot activate client");
  107. return 1;
  108. }
  109. sleep (-1);
  110. exit (0);
  111. }