Jack2  1.9.9
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 JackCoreMidiPort::JackCoreMidiPort(double time_ratio)
29 {
30  initialized = false;
31  this->time_ratio = time_ratio;
32 }
33 
34 JackCoreMidiPort::~JackCoreMidiPort()
35 {
36  // Empty
37 }
38 
39 const char *
40 JackCoreMidiPort::GetAlias()
41 {
42  assert(initialized);
43  return alias;
44 }
45 
46 MIDIEndpointRef
47 JackCoreMidiPort::GetEndpoint()
48 {
49  assert(initialized);
50  return endpoint;
51 }
52 
53 const char *
54 JackCoreMidiPort::GetName()
55 {
56  assert(initialized);
57  return name;
58 }
59 
60 void
61 JackCoreMidiPort::Initialize(const char *alias_name, const char *client_name,
62  const char *driver_name, int index,
63  MIDIEndpointRef endpoint, bool is_output)
64 {
65  char endpoint_name[REAL_JACK_PORT_NAME_SIZE];
66  CFStringRef endpoint_name_ref;
67  int num = index + 1;
68  Boolean res;
69  OSStatus result = MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName,
70  &endpoint_name_ref);
71  if (result != noErr) {
72  WriteMacOSError("JackCoreMidiPort::Initialize",
73  "MIDIObjectGetStringProperty", result);
74  goto get_basic_alias;
75  }
76  res = CFStringGetCString(endpoint_name_ref, endpoint_name,
77  sizeof(endpoint_name), 0);
78  CFRelease(endpoint_name_ref);
79  if (!res) {
80  jack_error("JackCoreMidiPort::Initialize - failed to allocate memory "
81  "for endpoint name.");
82  get_basic_alias:
83  snprintf(alias, sizeof(alias), "%s:%s:%s%d", alias_name,
84  driver_name, is_output ? "in" : "out", num);
85  } else {
86  snprintf(alias, sizeof(alias), "%s:%s:%s%d", alias_name,
87  endpoint_name, is_output ? "in" : "out", num);
88  }
89  snprintf(name, sizeof(name), "%s:%s_%d", client_name,
90  is_output ? "playback" : "capture", num);
91  this->endpoint = endpoint;
92  initialized = true;
93 }
SERVER_EXPORT void jack_error(const char *fmt,...)
Definition: JackError.cpp:91