Jack2 1.9.8

JackCoreMidiVirtualOutputPort.cpp

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 "JackCoreMidiUtil.h"
00024 #include "JackCoreMidiVirtualOutputPort.h"
00025 
00026 using Jack::JackCoreMidiVirtualOutputPort;
00027 
00028 JackCoreMidiVirtualOutputPort::
00029 JackCoreMidiVirtualOutputPort(const char *alias_name, const char *client_name,
00030                               const char *driver_name, int index,
00031                               MIDIClientRef client, double time_ratio,
00032                               size_t max_bytes,
00033                               size_t max_messages):
00034     JackCoreMidiOutputPort(time_ratio, max_bytes,
00035                            max_messages)
00036 {
00037     std::stringstream stream;
00038     stream << "virtual" << (index + 1);
00039     CFStringRef name = CFStringCreateWithCString(0, stream.str().c_str(),
00040                                                  CFStringGetSystemEncoding());
00041     if (! name) {
00042         throw std::bad_alloc();
00043     }
00044     MIDIEndpointRef source;
00045     OSStatus status = MIDISourceCreate(client, name, &source);
00046     CFRelease(name);
00047     if (status != noErr) {
00048         throw std::runtime_error(GetMacOSErrorString(status));
00049     }
00050     Initialize(alias_name, client_name, driver_name, index, source, 0);
00051 }
00052 
00053 JackCoreMidiVirtualOutputPort::~JackCoreMidiVirtualOutputPort()
00054 {
00055     OSStatus status = MIDIEndpointDispose(GetEndpoint());
00056     if (status != noErr) {
00057         WriteMacOSError("JackCoreMidiVirtualOutputPort [destructor]",
00058                         "MIDIEndpointDispose", status);
00059     }
00060 }
00061 
00062 bool
00063 JackCoreMidiVirtualOutputPort::SendPacketList(MIDIPacketList *packet_list)
00064 {
00065     OSStatus status = MIDIReceived(endpoint, packet_list);
00066     bool result = status == noErr;
00067     if (! result) {
00068         WriteMacOSError("JackCoreMidiVirtualOutputPort::SendPacketList",
00069                         "MIDIReceived", status);
00070     }
00071     return result;
00072 }