Jack2  1.9.10
JackCoreMidiPort.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 <cassert>
00021 
00022 #include "JackCoreMidiPort.h"
00023 #include "JackCoreMidiUtil.h"
00024 #include "JackError.h"
00025 
00026 using Jack::JackCoreMidiPort;
00027 
00028 std::set<MIDIEndpointRef> JackCoreMidiPort::endpoint_list;
00029 
00030 bool JackCoreMidiPort::IsInternalPort(MIDIObjectRef port_aux)
00031 {
00032     MIDIEndpointRef port = (MIDIEndpointRef)port_aux;
00033     return std::find(endpoint_list.begin(), endpoint_list.end(), port) != endpoint_list.end();
00034 }
00035 
00036 JackCoreMidiPort::JackCoreMidiPort(double time_ratio)
00037 {
00038     initialized = false;
00039     this->time_ratio = time_ratio;
00040 }
00041 
00042 JackCoreMidiPort::~JackCoreMidiPort()
00043 {
00044     // Empty
00045 }
00046 
00047 const char *
00048 JackCoreMidiPort::GetAlias()
00049 {
00050     assert(initialized);
00051     return alias;
00052 }
00053 
00054 MIDIEndpointRef
00055 JackCoreMidiPort::GetEndpoint()
00056 {
00057     assert(initialized);
00058     return endpoint;
00059 }
00060 
00061 const char *
00062 JackCoreMidiPort::GetName()
00063 {
00064     assert(initialized);
00065     return name;
00066 }
00067 
00068 void
00069 JackCoreMidiPort::Initialize(const char *alias_name, const char *client_name,
00070                              const char *driver_name, int index,
00071                              MIDIEndpointRef endpoint, bool is_output)
00072 {
00073     char endpoint_name[REAL_JACK_PORT_NAME_SIZE];
00074     CFStringRef endpoint_name_ref;
00075     int num = index + 1;
00076     Boolean res;
00077     OSStatus result = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName,
00078                                                   &endpoint_name_ref);
00079     if (result != noErr) {
00080         WriteMacOSError("JackCoreMidiPort::Initialize",
00081                         "MIDIObjectGetStringProperty", result);
00082         goto get_basic_alias;
00083     }
00084     res = CFStringGetCString(endpoint_name_ref, endpoint_name,
00085                                 sizeof(endpoint_name), 0);
00086     CFRelease(endpoint_name_ref);
00087     if (!res) {
00088         jack_error("JackCoreMidiPort::Initialize - failed to allocate memory "
00089                    "for endpoint name.");
00090     get_basic_alias:
00091         snprintf(alias, sizeof(alias), "%s:%s:%s%d", alias_name,
00092                  driver_name, is_output ? "in" : "out", num);
00093     } else {
00094         snprintf(alias, sizeof(alias), "%s:%s:%s%d", alias_name,
00095                  endpoint_name, is_output ? "in" : "out", num);
00096     }
00097     snprintf(name, sizeof(name), "%s:%s_%d", client_name,
00098              is_output ? "playback" : "capture", num);
00099     this->endpoint = endpoint;
00100     initialized = true;
00101 }