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.

94 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[REAL_JACK_PORT_NAME_SIZE];
  53. CFStringRef endpoint_name_ref;
  54. int num = index + 1;
  55. Boolean res;
  56. OSStatus result = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName,
  57. &endpoint_name_ref);
  58. if (result != noErr) {
  59. WriteMacOSError("JackCoreMidiPort::Initialize",
  60. "MIDIObjectGetStringProperty", result);
  61. goto get_basic_alias;
  62. }
  63. res = CFStringGetCString(endpoint_name_ref, endpoint_name,
  64. sizeof(endpoint_name), 0);
  65. CFRelease(endpoint_name_ref);
  66. if (!res) {
  67. jack_error("JackCoreMidiPort::Initialize - failed to allocate memory "
  68. "for endpoint name.");
  69. get_basic_alias:
  70. snprintf(alias, sizeof(alias), "%s:%s:%s%d", alias_name,
  71. driver_name, is_output ? "in" : "out", num);
  72. } else {
  73. snprintf(alias, sizeof(alias), "%s:%s:%s%d", alias_name,
  74. endpoint_name, is_output ? "in" : "out", num);
  75. }
  76. snprintf(name, sizeof(name), "%s:%s_%d", client_name,
  77. is_output ? "playback" : "capture", num);
  78. this->endpoint = endpoint;
  79. initialized = true;
  80. }