Jack2  1.9.10
JackCoreMidiPort.cpp
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 
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 void
69 JackCoreMidiPort::Initialize(const char *alias_name, const char *client_name,
70  const char *driver_name, int index,
71  MIDIEndpointRef endpoint, bool is_output)
72 {
73  char endpoint_name[REAL_JACK_PORT_NAME_SIZE];
74  CFStringRef endpoint_name_ref;
75  int num = index + 1;
76  Boolean res;
77  OSStatus result = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName,
78  &endpoint_name_ref);
79  if (result != noErr) {
80  WriteMacOSError("JackCoreMidiPort::Initialize",
81  "MIDIObjectGetStringProperty", result);
82  goto get_basic_alias;
83  }
84  res = CFStringGetCString(endpoint_name_ref, endpoint_name,
85  sizeof(endpoint_name), 0);
86  CFRelease(endpoint_name_ref);
87  if (!res) {
88  jack_error("JackCoreMidiPort::Initialize - failed to allocate memory "
89  "for endpoint name.");
90  get_basic_alias:
91  snprintf(alias, sizeof(alias), "%s:%s:%s%d", alias_name,
92  driver_name, is_output ? "in" : "out", num);
93  } else {
94  snprintf(alias, sizeof(alias), "%s:%s:%s%d", alias_name,
95  endpoint_name, is_output ? "in" : "out", num);
96  }
97  snprintf(name, sizeof(name), "%s:%s_%d", client_name,
98  is_output ? "playback" : "capture", num);
99  this->endpoint = endpoint;
100  initialized = true;
101 }