Jack2  1.9.8
JackCoreMidiPhysicalOutputPort.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 "JackCoreMidiPhysicalOutputPort.h"
00024 #include "JackCoreMidiUtil.h"
00025 
00026 using Jack::JackCoreMidiPhysicalOutputPort;
00027 
00028 JackCoreMidiPhysicalOutputPort::
00029 JackCoreMidiPhysicalOutputPort(const char *alias_name, const char *client_name,
00030                                const char *driver_name, int index,
00031                                MIDIClientRef client,
00032                                MIDIPortRef internal_output, double time_ratio,
00033                                size_t max_bytes,
00034                                size_t max_messages):
00035     JackCoreMidiOutputPort(time_ratio, max_bytes,
00036                            max_messages)
00037 {
00038     MIDIEndpointRef destination = MIDIGetDestination(index);
00039     if (! destination) {
00040         // X: Can we get a better error message?
00041         std::stringstream stream;
00042         stream << "The destination at index '" << index
00043                << "' is not available";
00044         throw std::runtime_error(stream.str().c_str());
00045     }
00046     SInt32 advance_schedule_time;
00047     OSStatus status =
00048         MIDIObjectGetIntegerProperty(destination,
00049                                      kMIDIPropertyAdvanceScheduleTimeMuSec,
00050                                      &advance_schedule_time);
00051     if (status != noErr) {
00052         WriteMacOSError("JackCoreMidiPhysicalOutputPort [constructor]",
00053                         "MIDIObjectGetIntegerProperty", status);
00054         advance_schedule_time = 0;
00055     } else if (advance_schedule_time < 0) {
00056         advance_schedule_time = 0;
00057     }
00058     Initialize(alias_name, client_name, driver_name, index, destination,
00059                advance_schedule_time);
00060     this->internal_output = internal_output;
00061 }
00062 
00063 JackCoreMidiPhysicalOutputPort::~JackCoreMidiPhysicalOutputPort()
00064 {
00065     // Empty
00066 }
00067 
00068 bool
00069 JackCoreMidiPhysicalOutputPort::SendPacketList(MIDIPacketList *packet_list)
00070 {
00071     OSStatus status = MIDISend(internal_output, endpoint, packet_list);
00072     bool result = status == noErr;
00073     if (! result) {
00074         WriteMacOSError("JackCoreMidiPhysicalOutputPort::SendPacketList",
00075                         "MIDISend", status);
00076     }
00077     return result;
00078 }