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.

102 lines
2.9KB

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