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;
41 // unsigned long count;
43 OSStatus err
= AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices
, &count
, 0);
44 AudioDeviceID
*devices
= (AudioDeviceID
*)malloc(count
);
45 err
= AudioHardwareGetProperty(kAudioHardwarePropertyDevices
, &count
, devices
);
46 if (err
!=kAudioHardwareNoError
)
52 numDevices
= count
/ sizeof(AudioDeviceID
);
58 for (i
=0; i
<numDevices
; i
++)
61 err
= AudioDeviceGetPropertyInfo(devices
[i
], 0, type
, kAudioDevicePropertyStreams
, &count
, &writeable
);
62 if (err
!=kAudioHardwareNoError
)
67 if (!count
) devices
[i
] = 0;
71 else num
= numDevices
;
73 PyrObject
* devArray
= newPyrArray(g
->gc
, num
* sizeof(PyrObject
), 0, true);
74 SetObject(a
, devArray
);
77 for (i
=0; i
<numDevices
; i
++)
79 if (!devices
[i
]) continue;
81 err
= AudioDeviceGetPropertyInfo(devices
[i
], 0, false, kAudioDevicePropertyDeviceName
, &count
, 0);
82 if (err
!= kAudioHardwareNoError
)
87 char *name
= (char*)malloc(count
);
88 err
= AudioDeviceGetProperty(devices
[i
], 0, false, kAudioDevicePropertyDeviceName
, &count
, name
);
89 if (err
!= kAudioHardwareNoError
)
95 PyrString
*string
= newPyrString(g
->gc
, name
, 0, true);
96 SetObject(devArray
->slots
+j
, string
);
98 g
->gc
->GCWrite(devArray
, (PyrObject
*)string
);
108 int prListAudioDevices(struct VMGlobals
*g
, int numArgsPushed
)
112 slotIntVal(g
->sp
, &out
);
113 slotIntVal(g
->sp
-1, &in
);
116 if (in
&& out
) type
= BOTH
;
117 else if (in
) type
= IN
;
120 if (listDevices(g
, type
)) return errNone
;
124 void initCoreAudioPrimitives()
126 definePrimitive(nextPrimitiveIndex(), 0, "_ListAudioDevices", prListAudioDevices
, 3, 0);