Jack2 1.9.10
|
00001 /* 00002 Copyright (C) 2011 Devin Anderson 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation; either version 2 of the License, or 00007 (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with this program; if not, write to the Free Software 00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 00018 */ 00019 00020 #include <sstream> 00021 #include <stdexcept> 00022 00023 #include "JackError.h" 00024 #include "JackCoreMidiUtil.h" 00025 #include "JackCoreMidiVirtualInputPort.h" 00026 00027 using Jack::JackCoreMidiVirtualInputPort; 00028 00030 // Static callbacks 00032 00033 void 00034 JackCoreMidiVirtualInputPort:: 00035 HandleInputEvent(const MIDIPacketList *packet_list, void *port, 00036 void */*src_ref*/) 00037 { 00038 ((JackCoreMidiVirtualInputPort *) port)->ProcessCoreMidi(packet_list); 00039 } 00040 00042 // Class 00044 00045 JackCoreMidiVirtualInputPort:: 00046 JackCoreMidiVirtualInputPort(const char *alias_name, const char *client_name, 00047 const char *driver_name, int base_index, int index, 00048 MIDIClientRef client, double time_ratio, 00049 size_t max_bytes, size_t max_messages): 00050 JackCoreMidiInputPort(time_ratio, max_bytes, max_messages) 00051 { 00052 std::stringstream stream; 00053 stream << "virtual" << (base_index + 1); 00054 CFStringRef name = CFStringCreateWithCString(0, stream.str().c_str(), 00055 CFStringGetSystemEncoding()); 00056 if (! name) { 00057 throw std::bad_alloc(); 00058 } 00059 MIDIEndpointRef destination; 00060 OSStatus status = MIDIDestinationCreate(client, name, HandleInputEvent, 00061 this, &destination); 00062 00063 /* 00064 SInt32 value; 00065 status = MIDIObjectGetIntegerProperty(destination, kMIDIPropertyUniqueID, &value); 00066 if (status == noErr) { 00067 jack_info("kMIDIPropertyUniqueID %d", value); 00068 } 00069 */ 00070 00071 CFRelease(name); 00072 if (status != noErr) { 00073 throw std::runtime_error(GetMacOSErrorString(status)); 00074 } 00075 Initialize(alias_name, client_name, driver_name, index, destination); 00076 00077 // Keep in global list (that keeps growing during the whole session...) 00078 endpoint_list.insert(endpoint); 00079 } 00080 00081 JackCoreMidiVirtualInputPort::~JackCoreMidiVirtualInputPort() 00082 { 00083 OSStatus status = MIDIEndpointDispose(GetEndpoint()); 00084 if (status != noErr) { 00085 WriteMacOSError("JackCoreMidiVirtualInputPort [destructor]", 00086 "MIDIEndpointDispose", status); 00087 } 00088 }