00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
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 }