Jack2 1.9.10

JackCoreMidiPhysicalInputPort.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 "JackCoreMidiPhysicalInputPort.h"
00024 #include "JackCoreMidiUtil.h"
00025 
00026 using Jack::JackCoreMidiPhysicalInputPort;
00027 
00028 JackCoreMidiPhysicalInputPort::
00029 JackCoreMidiPhysicalInputPort(const char *alias_name, const char *client_name,
00030                               const char *driver_name, int index,
00031                               MIDIClientRef client, MIDIPortRef internal_input,
00032                               double time_ratio, size_t max_bytes,
00033                               size_t max_messages):
00034     JackCoreMidiInputPort(time_ratio, max_bytes, max_messages)
00035 {
00036     MIDIEndpointRef source = MIDIGetSource(index);
00037     if (! source) {
00038         // X: Is there a way to get a better error message?
00039         std::stringstream stream;
00040         stream << "The source at index '" << index << "' is not available";
00041         throw std::runtime_error(stream.str().c_str());
00042     }
00043     OSStatus status = MIDIPortConnectSource(internal_input, source, this);
00044     if (status != noErr) {
00045         throw std::runtime_error(GetMacOSErrorString(status));
00046     }
00047     Initialize(alias_name, client_name, driver_name, index, source);
00048 }
00049 
00050 JackCoreMidiPhysicalInputPort::~JackCoreMidiPhysicalInputPort()
00051 {
00052     // Empty
00053 }