jack2 codebase
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.

93 lines
2.7KB

  1. /*
  2. Copyright (C) 2011 Devin Anderson
  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 <cassert>
  16. #include "JackCoreMidiPort.h"
  17. #include "JackCoreMidiUtil.h"
  18. #include "JackError.h"
  19. using Jack::JackCoreMidiPort;
  20. JackCoreMidiPort::JackCoreMidiPort(double time_ratio)
  21. {
  22. initialized = false;
  23. this->time_ratio = time_ratio;
  24. }
  25. JackCoreMidiPort::~JackCoreMidiPort()
  26. {
  27. // Empty
  28. }
  29. const char *
  30. JackCoreMidiPort::GetAlias()
  31. {
  32. assert(initialized);
  33. return alias;
  34. }
  35. MIDIEndpointRef
  36. JackCoreMidiPort::GetEndpoint()
  37. {
  38. assert(initialized);
  39. return endpoint;
  40. }
  41. const char *
  42. JackCoreMidiPort::GetName()
  43. {
  44. assert(initialized);
  45. return name;
  46. }
  47. void
  48. JackCoreMidiPort::Initialize(const char *alias_name, const char *client_name,
  49. const char *driver_name, int index,
  50. MIDIEndpointRef endpoint, bool is_output)
  51. {
  52. char endpoint_name[JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE];
  53. CFStringRef endpoint_name_ref;
  54. int num = index + 1;
  55. OSStatus result = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName,
  56. &endpoint_name_ref);
  57. if (result != noErr) {
  58. WriteMacOSError("JackCoreMidiPort::Initialize",
  59. "MIDIObjectGetStringProperty", result);
  60. goto get_basic_alias;
  61. }
  62. result = CFStringGetCString(endpoint_name_ref, endpoint_name,
  63. sizeof(endpoint_name), 0);
  64. CFRelease(endpoint_name_ref);
  65. if (result != noErr) {
  66. jack_error("JackCoreMidiPort::Initialize - failed to allocate memory "
  67. "for endpoint name.");
  68. get_basic_alias:
  69. snprintf(alias, sizeof(alias) - 1, "%s:%s:%s%d", alias_name,
  70. driver_name, is_output ? "out" : "in", num);
  71. } else {
  72. snprintf(alias, sizeof(alias) - 1, "%s:%s:%s%d", alias_name,
  73. endpoint_name, is_output ? "out" : "in", num);
  74. }
  75. snprintf(name, sizeof(name) - 1, "%s:%s_%d", client_name,
  76. is_output ? "playback" : "capture", num);
  77. this->endpoint = endpoint;
  78. initialized = true;
  79. }