2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include <CoreAudio/AudioHardware.h>
24 #include "VMGlobals.h"
25 #include "PyrKernel.h"
26 #include "PyrPrimitive.h"
36 int listDevices(struct VMGlobals
*g
, int type
)
38 int numDevices
, num
= 0;
40 AudioObjectPropertyAddress propertyAddress
;
41 propertyAddress
.mSelector
= kAudioHardwarePropertyDevices
;
42 propertyAddress
.mScope
= kAudioObjectPropertyScopeGlobal
;
43 propertyAddress
.mElement
= kAudioObjectPropertyElementMaster
;
45 // unsigned long count;
47 // OSStatus err = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &count, 0);
48 OSStatus err
= AudioObjectGetPropertyDataSize(kAudioObjectSystemObject
, &propertyAddress
, 0, NULL
, &count
);
49 AudioDeviceID
*devices
= (AudioDeviceID
*)malloc(count
);
50 // err = AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &count, devices);
51 err
= AudioObjectGetPropertyData(kAudioObjectSystemObject
, &propertyAddress
, 0, NULL
, &count
, devices
);
52 if (err
!=kAudioHardwareNoError
)
58 numDevices
= count
/ sizeof(AudioDeviceID
);
66 propertyAddress
.mScope
= kAudioDevicePropertyScopeOutput
;
68 propertyAddress
.mScope
= kAudioDevicePropertyScopeInput
;
71 for (i
=0; i
<numDevices
; i
++)
74 propertyAddress
.mSelector
= kAudioDevicePropertyStreams
;
75 // err = AudioDeviceGetPropertyInfo(devices[i], 0, type, kAudioDevicePropertyStreams, &count, &writeable);
77 err
= AudioObjectGetPropertyDataSize(devices
[i
], &propertyAddress
, 0, NULL
, &count
);
79 if (err
!=kAudioHardwareNoError
)
85 err
= AudioObjectIsPropertySettable(devices
[i
], &propertyAddress
, &writeable
);
87 if (err
!=kAudioHardwareNoError
)
92 if (!count
) devices
[i
] = 0;
96 else num
= numDevices
;
98 PyrObject
* devArray
= newPyrArray(g
->gc
, num
* sizeof(PyrObject
), 0, true);
99 SetObject(a
, devArray
);
102 for (i
=0; i
<numDevices
; i
++)
104 if (!devices
[i
]) continue;
106 propertyAddress
.mScope
= kAudioObjectPropertyScopeGlobal
;
107 propertyAddress
.mSelector
= kAudioDevicePropertyDeviceName
;
109 // err = AudioDeviceGetPropertyInfo(devices[i], 0, false, kAudioDevicePropertyDeviceName, &count, 0);
111 err
= AudioObjectGetPropertyDataSize(devices
[i
], &propertyAddress
, 0, NULL
, &count
);
113 if (err
!= kAudioHardwareNoError
)
118 char *name
= (char*)malloc(count
);
119 // err = AudioDeviceGetProperty(devices[i], 0, false, kAudioDevicePropertyDeviceName, &count, name);
120 err
= AudioObjectGetPropertyData(devices
[i
], &propertyAddress
, 0, NULL
, &count
, name
);
121 if (err
!= kAudioHardwareNoError
)
127 PyrString
*string
= newPyrString(g
->gc
, name
, 0, true);
128 SetObject(devArray
->slots
+j
, string
);
130 g
->gc
->GCWrite(devArray
, (PyrObject
*)string
);
140 int prListAudioDevices(struct VMGlobals
*g
, int numArgsPushed
)
144 slotIntVal(g
->sp
, &out
);
145 slotIntVal(g
->sp
-1, &in
);
148 if (in
&& out
) type
= BOTH
;
149 else if (in
) type
= IN
;
152 if (listDevices(g
, type
)) return errNone
;
156 void initCoreAudioPrimitives()
158 definePrimitive(nextPrimitiveIndex(), 0, "_ListAudioDevices", prListAudioDevices
, 3, 0);