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.

143 lines
3.9KB

  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_rename_callback (jack_port_id_t port, const char* old_name, const char* new_name)
  25. {
  26. printf ("Port %d renamed from %s to %s\n", port, old_name, new_name);
  27. }
  28. void
  29. port_callback (jack_port_id_t port, int yn, void* arg)
  30. {
  31. printf ("Port %d %s\n", port, (yn ? "registered" : "unregistered"));
  32. }
  33. void
  34. connect_callback (jack_port_id_t a, jack_port_id_t b, int yn, void* arg)
  35. {
  36. printf ("Ports %d and %d %s\n", a, b, (yn ? "connected" : "disconnected"));
  37. }
  38. void
  39. client_callback (const char* client, int yn, void* arg)
  40. {
  41. printf ("Client %s %s\n", client, (yn ? "registered" : "unregistered"));
  42. }
  43. int
  44. graph_callback (void* arg)
  45. {
  46. printf ("Graph reordered\n");
  47. return 0;
  48. }
  49. void
  50. propchange (jack_uuid_t subject, const char* key, jack_property_change_t change)
  51. {
  52. char buf[JACK_UUID_STRING_SIZE];
  53. const char* action = "";
  54. switch (change) {
  55. case PropertyCreated:
  56. action = "created";
  57. break;
  58. case PropertyChanged:
  59. action = "changed";
  60. break;
  61. case PropertyDeleted:
  62. action = "deleted";
  63. break;
  64. }
  65. if (jack_uuid_empty (subject)) {
  66. printf ("All properties changed!\n");
  67. } else {
  68. jack_uuid_unparse (subject, buf);
  69. if (key) {
  70. printf ("key [%s] for %s %s\n", key, buf, action);
  71. } else {
  72. printf ("all keys for %s %s\n", buf, action);
  73. }
  74. }
  75. }
  76. int
  77. main (int argc, char *argv[])
  78. {
  79. jack_client_t *client;
  80. jack_options_t options = JackNullOption;
  81. jack_status_t status;
  82. if ((client = jack_client_open ("event-monitor", options, &status, NULL)) == 0) {
  83. fprintf (stderr, "jack_client_open() failed, "
  84. "status = 0x%2.0x\n", status);
  85. if (status & JackServerFailed) {
  86. fprintf (stderr, "Unable to connect to JACK server\n");
  87. }
  88. return 1;
  89. }
  90. if (jack_set_port_registration_callback (client, port_callback, NULL)) {
  91. fprintf (stderr, "cannot set port registration callback\n");
  92. return 1;
  93. }
  94. if (jack_set_port_rename_callback (client, port_rename_callback, NULL)) {
  95. fprintf (stderr, "cannot set port registration callback\n");
  96. return 1;
  97. }
  98. if (jack_set_port_connect_callback (client, connect_callback, NULL)) {
  99. fprintf (stderr, "cannot set port connect callback\n");
  100. return 1;
  101. }
  102. if (jack_set_client_registration_callback (client, client_callback, NULL)) {
  103. fprintf (stderr, "cannot set client registration callback\n");
  104. return 1;
  105. }
  106. if (jack_set_graph_order_callback (client, graph_callback, NULL)) {
  107. fprintf (stderr, "cannot set graph order registration callback\n");
  108. return 1;
  109. }
  110. if (jack_set_property_change_callback (client, (JackPropertyChangeCallback) propchange, 0)) {
  111. fprintf (stderr, "cannot set property change callback\n");
  112. return 1;
  113. }
  114. if (jack_activate (client)) {
  115. fprintf (stderr, "cannot activate client");
  116. return 1;
  117. }
  118. sleep (-1);
  119. exit (0);
  120. }