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 "JackCoreMidiVirtualOutputPort.h" 00026 00027 using Jack::JackCoreMidiVirtualOutputPort; 00028 00029 JackCoreMidiVirtualOutputPort:: 00030 JackCoreMidiVirtualOutputPort(const char *alias_name, const char *client_name, 00031 const char *driver_name, int base_index, int index, 00032 MIDIClientRef client, double time_ratio, 00033 size_t max_bytes, 00034 size_t max_messages): 00035 JackCoreMidiOutputPort(time_ratio, max_bytes, 00036 max_messages) 00037 { 00038 std::stringstream stream; 00039 stream << "virtual" << (base_index + 1); 00040 CFStringRef name = CFStringCreateWithCString(0, stream.str().c_str(), 00041 CFStringGetSystemEncoding()); 00042 if (! name) { 00043 throw std::bad_alloc(); 00044 } 00045 MIDIEndpointRef source; 00046 OSStatus status = MIDISourceCreate(client, name, &source); 00047 00048 /* 00049 SInt32 value; 00050 status = MIDIObjectGetIntegerProperty(source, kMIDIPropertyUniqueID, &value); 00051 if (status == noErr) { 00052 jack_info("kMIDIPropertyUniqueID %d", value); 00053 } 00054 */ 00055 00056 CFRelease(name); 00057 if (status != noErr) { 00058 throw std::runtime_error(GetMacOSErrorString(status)); 00059 } 00060 Initialize(alias_name, client_name, driver_name, index, source, 0); 00061 00062 // Keep in global list (that keeps growing during the whole session...) 00063 endpoint_list.insert(GetEndpoint()); 00064 } 00065 00066 JackCoreMidiVirtualOutputPort::~JackCoreMidiVirtualOutputPort() 00067 { 00068 OSStatus status = MIDIEndpointDispose(GetEndpoint()); 00069 if (status != noErr) { 00070 WriteMacOSError("JackCoreMidiVirtualOutputPort [destructor]", 00071 "MIDIEndpointDispose", status); 00072 } 00073 } 00074 00075 bool 00076 JackCoreMidiVirtualOutputPort::SendPacketList(MIDIPacketList *packet_list) 00077 { 00078 OSStatus status = MIDIReceived(endpoint, packet_list); 00079 bool result = status == noErr; 00080 if (! result) { 00081 WriteMacOSError("JackCoreMidiVirtualOutputPort::SendPacketList", 00082 "MIDIReceived", status); 00083 } 00084 return result; 00085 }