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