| 1 |
/* |
| 2 |
Copyright (C) 2011 Devin Anderson |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation; either version 2 of the License, or |
| 7 |
(at your option) any later version. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU General Public License |
| 15 |
along with this program; if not, write to the Free Software |
| 16 |
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 17 |
|
| 18 |
*/ |
| 19 |
|
| 20 |
#include <cassert> |
| 21 |
|
| 22 |
#include "JackCoreMidiPort.h" |
| 23 |
#include "JackCoreMidiUtil.h" |
| 24 |
#include "JackError.h" |
| 25 |
|
| 26 |
using Jack::JackCoreMidiPort; |
| 27 |
|
| 28 |
std::set<MIDIEndpointRef> JackCoreMidiPort::endpoint_list; |
| 29 |
|
| 30 |
bool JackCoreMidiPort::IsInternalPort(MIDIObjectRef port_aux) |
| 31 |
{ |
| 32 |
MIDIEndpointRef port = (MIDIEndpointRef)port_aux; |
| 33 |
return std::find(endpoint_list.begin(), endpoint_list.end(), port) != endpoint_list.end(); |
| 34 |
} |
| 35 |
|
| 36 |
JackCoreMidiPort::JackCoreMidiPort(double time_ratio) |
| 37 |
{ |
| 38 |
initialized = false; |
| 39 |
this->time_ratio = time_ratio; |
| 40 |
} |
| 41 |
|
| 42 |
JackCoreMidiPort::~JackCoreMidiPort() |
| 43 |
{ |
| 44 |
// Empty |
| 45 |
} |
| 46 |
|
| 47 |
const char * |
| 48 |
JackCoreMidiPort::GetAlias() |
| 49 |
{ |
| 50 |
assert(initialized); |
| 51 |
return alias; |
| 52 |
} |
| 53 |
|
| 54 |
MIDIEndpointRef |
| 55 |
JackCoreMidiPort::GetEndpoint() |
| 56 |
{ |
| 57 |
assert(initialized); |
| 58 |
return endpoint; |
| 59 |
} |
| 60 |
|
| 61 |
const char * |
| 62 |
JackCoreMidiPort::GetName() |
| 63 |
{ |
| 64 |
assert(initialized); |
| 65 |
return name; |
| 66 |
} |
| 67 |
|
| 68 |
const char * |
| 69 |
JackCoreMidiPort::GetDeviceName() |
| 70 |
{ |
| 71 |
assert(initialized); |
| 72 |
return device_name; |
| 73 |
} |
| 74 |
|
| 75 |
void |
| 76 |
JackCoreMidiPort::Initialize(const char *alias_name, const char *client_name, |
| 77 |
const char *driver_name, int index, |
| 78 |
MIDIEndpointRef endpoint, bool is_output) |
| 79 |
{ |
| 80 |
char endpoint_name[REAL_JACK_PORT_NAME_SIZE+1]; |
| 81 |
CFStringRef endpoint_name_ref; |
| 82 |
int num = index + 1; |
| 83 |
Boolean res; |
| 84 |
OSStatus result = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, |
| 85 |
&endpoint_name_ref); |
| 86 |
if (result != noErr) { |
| 87 |
WriteMacOSError("JackCoreMidiPort::Initialize", |
| 88 |
"MIDIObjectGetStringProperty", result); |
| 89 |
goto get_basic_alias; |
| 90 |
} |
| 91 |
res = CFStringGetCString(endpoint_name_ref, endpoint_name, |
| 92 |
sizeof(endpoint_name), 0); |
| 93 |
CFRelease(endpoint_name_ref); |
| 94 |
if (!res) { |
| 95 |
jack_error("JackCoreMidiPort::Initialize - failed to allocate memory " |
| 96 |
"for endpoint name."); |
| 97 |
get_basic_alias: |
| 98 |
snprintf(alias, sizeof(alias), "%s:%s:%s%d", alias_name, |
| 99 |
driver_name, is_output ? "in" : "out", num); |
| 100 |
} else { |
| 101 |
snprintf(alias, sizeof(alias), "%s:%s:%s%d", alias_name, |
| 102 |
endpoint_name, is_output ? "in" : "out", num); |
| 103 |
} |
| 104 |
snprintf(name, sizeof(name), "%s:%s_%d", client_name, |
| 105 |
is_output ? "playback" : "capture", num); |
| 106 |
strncpy(device_name, endpoint_name, sizeof(device_name) - 1); |
| 107 |
this->endpoint = endpoint; |
| 108 |
initialized = true; |
| 109 |
} |