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.

87 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 <sstream>
  16. #include <stdexcept>
  17. #include "JackError.h"
  18. #include "JackCoreMidiUtil.h"
  19. #include "JackCoreMidiVirtualInputPort.h"
  20. using Jack::JackCoreMidiVirtualInputPort;
  21. ///////////////////////////////////////////////////////////////////////////////
  22. // Static callbacks
  23. ///////////////////////////////////////////////////////////////////////////////
  24. void
  25. JackCoreMidiVirtualInputPort::
  26. HandleInputEvent(const MIDIPacketList *packet_list, void *port,
  27. void */*src_ref*/)
  28. {
  29. ((JackCoreMidiVirtualInputPort *) port)->ProcessCoreMidi(packet_list);
  30. }
  31. ///////////////////////////////////////////////////////////////////////////////
  32. // Class
  33. ///////////////////////////////////////////////////////////////////////////////
  34. JackCoreMidiVirtualInputPort::
  35. JackCoreMidiVirtualInputPort(const char *alias_name, const char *client_name,
  36. const char *driver_name, int index,
  37. MIDIClientRef client, double time_ratio,
  38. size_t max_bytes, size_t max_messages):
  39. JackCoreMidiInputPort(time_ratio, max_bytes, max_messages)
  40. {
  41. CFStringRef name = CFStringCreateWithCString(0, "virtual",
  42. CFStringGetSystemEncoding());
  43. if (! name) {
  44. throw std::bad_alloc();
  45. }
  46. MIDIEndpointRef destination;
  47. OSStatus status = MIDIDestinationCreate(client, name, HandleInputEvent,
  48. this, &destination);
  49. /*
  50. SInt32 value;
  51. status = MIDIObjectGetIntegerProperty(destination, kMIDIPropertyUniqueID, &value);
  52. if (status == noErr) {
  53. jack_info("kMIDIPropertyUniqueID %d", value);
  54. }
  55. */
  56. CFRelease(name);
  57. if (status != noErr) {
  58. throw std::runtime_error(GetMacOSErrorString(status));
  59. }
  60. Initialize(alias_name, client_name, driver_name, index, destination);
  61. // Keep in global list (that keeps growing during the whole session...)
  62. endpoint_list.insert(endpoint);
  63. }
  64. JackCoreMidiVirtualInputPort::~JackCoreMidiVirtualInputPort()
  65. {
  66. OSStatus status = MIDIEndpointDispose(GetEndpoint());
  67. if (status != noErr) {
  68. WriteMacOSError("JackCoreMidiVirtualInputPort [destructor]",
  69. "MIDIEndpointDispose", status);
  70. }
  71. }