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.

89 lines
3.2KB

  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. std::stringstream stream;
  42. stream << "virtual" << (index + 1);
  43. CFStringRef name = CFStringCreateWithCString(0, stream.str().c_str(),
  44. CFStringGetSystemEncoding());
  45. if (! name) {
  46. throw std::bad_alloc();
  47. }
  48. MIDIEndpointRef destination;
  49. OSStatus status = MIDIDestinationCreate(client, name, HandleInputEvent,
  50. this, &destination);
  51. /*
  52. SInt32 value;
  53. status = MIDIObjectGetIntegerProperty(destination, kMIDIPropertyUniqueID, &value);
  54. if (status == noErr) {
  55. jack_info("kMIDIPropertyUniqueID %d", value);
  56. }
  57. */
  58. CFRelease(name);
  59. if (status != noErr) {
  60. throw std::runtime_error(GetMacOSErrorString(status));
  61. }
  62. Initialize(alias_name, client_name, driver_name, index, destination);
  63. // Keep in global list (that keeps growing during the whole session...)
  64. endpoint_list.insert(endpoint);
  65. }
  66. JackCoreMidiVirtualInputPort::~JackCoreMidiVirtualInputPort()
  67. {
  68. OSStatus status = MIDIEndpointDispose(GetEndpoint());
  69. if (status != noErr) {
  70. WriteMacOSError("JackCoreMidiVirtualInputPort [destructor]",
  71. "MIDIEndpointDispose", status);
  72. }
  73. }