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.

111 lines
3.1KB

  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 <algorithm>
  17. #include "JackCoreMidiPort.h"
  18. #include "JackCoreMidiUtil.h"
  19. #include "JackError.h"
  20. using Jack::JackCoreMidiPort;
  21. std::set<MIDIEndpointRef> JackCoreMidiPort::endpoint_list;
  22. bool JackCoreMidiPort::IsInternalPort(MIDIObjectRef port_aux)
  23. {
  24. MIDIEndpointRef port = (MIDIEndpointRef)port_aux;
  25. return std::find(endpoint_list.begin(), endpoint_list.end(), port) != endpoint_list.end();
  26. }
  27. JackCoreMidiPort::JackCoreMidiPort(double time_ratio)
  28. {
  29. initialized = false;
  30. this->time_ratio = time_ratio;
  31. }
  32. JackCoreMidiPort::~JackCoreMidiPort()
  33. {
  34. // Empty
  35. }
  36. const char *
  37. JackCoreMidiPort::GetAlias()
  38. {
  39. assert(initialized);
  40. return alias;
  41. }
  42. MIDIEndpointRef
  43. JackCoreMidiPort::GetEndpoint()
  44. {
  45. assert(initialized);
  46. return endpoint;
  47. }
  48. const char *
  49. JackCoreMidiPort::GetName()
  50. {
  51. assert(initialized);
  52. return name;
  53. }
  54. const char *
  55. JackCoreMidiPort::GetDeviceName()
  56. {
  57. assert(initialized);
  58. return device_name;
  59. }
  60. void
  61. JackCoreMidiPort::Initialize(const char *alias_name, const char *client_name,
  62. const char *driver_name, int index,
  63. MIDIEndpointRef endpoint, bool is_output)
  64. {
  65. char endpoint_name[REAL_JACK_PORT_NAME_SIZE+1];
  66. CFStringRef endpoint_name_ref;
  67. int num = index + 1;
  68. Boolean res;
  69. OSStatus result = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName,
  70. &endpoint_name_ref);
  71. if (result != noErr) {
  72. WriteMacOSError("JackCoreMidiPort::Initialize",
  73. "MIDIObjectGetStringProperty", result);
  74. goto get_basic_alias;
  75. }
  76. res = CFStringGetCString(endpoint_name_ref, endpoint_name,
  77. sizeof(endpoint_name), 0);
  78. CFRelease(endpoint_name_ref);
  79. if (!res) {
  80. jack_error("JackCoreMidiPort::Initialize - failed to allocate memory "
  81. "for endpoint name.");
  82. get_basic_alias:
  83. snprintf(alias, sizeof(alias), "%s:%s:%s%d", alias_name,
  84. driver_name, is_output ? "in" : "out", num);
  85. } else {
  86. snprintf(alias, sizeof(alias), "%s:%s:%s%d", alias_name,
  87. endpoint_name, is_output ? "in" : "out", num);
  88. }
  89. snprintf(name, sizeof(name), "%s:%s_%d", client_name,
  90. is_output ? "playback" : "capture", num);
  91. strncpy(device_name, endpoint_name, sizeof(device_name) - 1);
  92. this->endpoint = endpoint;
  93. initialized = true;
  94. }