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