drumstick  1.0.0
maccommon.cpp
1 /*
2  Drumstick RT (realtime MIDI In/Out)
3  Copyright (C) 2009-2014 Pedro Lopez-Cabanillas <plcl@users.sf.net>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 #include "maccommon.h"
21 
22 #if QT_VERSION < QT_VERSION_CHECK(5,2,0)
23  QString CFStringToQString(CFStringRef str)
24  {
25  if (!str)
26  return QString();
27  CFIndex length = CFStringGetLength(str);
28  const UniChar *chars = CFStringGetCharactersPtr(str);
29  if (chars)
30  return QString(reinterpret_cast<const QChar *>(chars), length);
31  QVarLengthArray<UniChar> buffer(length);
32  CFStringGetCharacters(str, CFRangeMake(0, length), buffer.data());
33  return QString(reinterpret_cast<const QChar *>(buffer.constData()), length);
34  }
35 #endif
36 
37 QString getEndpointName(MIDIEndpointRef endpoint)
38 {
39  QString result;
40  CFStringRef str = 0;
41  MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
42  if (str != 0) {
43  result = QString::fromCFString(str);
44  CFRelease(str);
45  str = 0;
46  }
47  MIDIEntityRef entity = 0;
48  MIDIEndpointGetEntity(endpoint, &entity);
49  if (entity == 0)
50  return result;
51  if (result.isEmpty()) {
52  MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
53  if (str != 0) {
54  result = QString::fromCFString(str);
55  CFRelease(str);
56  str = 0;
57  }
58  }
59  MIDIDeviceRef device = 0;
60  MIDIEntityGetDevice (entity, &device);
61  if (device == 0)
62  return result;
63  MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
64  if (str != 0) {
65  QString s = QString::fromCFString(str);
66  CFRelease (str);
67  str = 0;
68  if (!result.startsWith(s, Qt::CaseInsensitive) )
69  result = (s + ' ' + result).trimmed();
70  }
71  return result;
72 }
73 
74 /* QString getEndpointName(MIDIEndpointRef endpoint)
75 {
76  QString result;
77  CFStringRef str = 0;
78  MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
79  if (str != 0) {
80  result = QString::fromCFString(str);
81  CFRelease(str);
82  str = 0;
83  }
84  MIDIEntityRef entity = 0;
85  MIDIEndpointGetEntity(endpoint, &entity);
86  if (entity == 0)
87  return result;
88  if (result.isEmpty()) {
89  MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
90  if (str != 0) {
91  result = QString::fromCFString(str);
92  CFRelease(str);
93  str = 0;
94  }
95  }
96  MIDIDeviceRef device = 0;
97  MIDIEntityGetDevice (entity, &device);
98  if (device == 0)
99  return result;
100  MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
101  if (str != 0) {
102  QString s =QString::fromCFString(str);
103  CFRelease (str);
104  str = 0;
105  if (!result.startsWith(s, Qt::CaseInsensitive) )
106  result = (s + ' ' + result).trimmed();
107  }
108  return result;
109 }
110 */