@@ -1162,6 +1162,94 @@ static int audiodevice_setbalance(lua_State* L) {
11621162
11631163}
11641164
1165+ // / hs.audiodevice:thru() -> bool or nil
1166+ // / Method
1167+ // / Get the play through (low latency/direct monitoring) state of the audio device
1168+ // /
1169+ // / Parameters:
1170+ // / * None
1171+ // /
1172+ // / Returns:
1173+ // / * True if the audio device has thru enabled, False if thru is disabled, nil if it does not support thru
1174+ // /
1175+ // / Notes:
1176+ // / * This method only works on devices that have hardware support (often microphones with a built-in headphone jack)
1177+ // / * This setting corresponds to the "Thru" setting in Audio MIDI Setup
1178+ static int audiodevice_thru (lua_State* L) {
1179+ LuaSkin *skin = [LuaSkin sharedWithState: L];
1180+ [skin checkArgs: LS_TUSERDATA, USERDATA_TAG, LS_TBREAK];
1181+
1182+ audioDeviceUserData *audioDevice = userdataToAudioDevice (L, 1 );
1183+ AudioDeviceID deviceId = audioDevice->deviceId ;
1184+ unsigned int scope;
1185+ UInt32 thru;
1186+ UInt32 thruSize = sizeof (UInt32);
1187+
1188+ if (isOutputDevice (deviceId)) {
1189+ scope = kAudioObjectPropertyScopeOutput ;
1190+ } else {
1191+ scope = kAudioObjectPropertyScopeInput ;
1192+ }
1193+
1194+ AudioObjectPropertyAddress propertyAddress = {
1195+ kAudioDevicePropertyPlayThru ,
1196+ scope,
1197+ kAudioObjectPropertyElementMain
1198+ };
1199+
1200+ if (AudioObjectHasProperty (deviceId, &propertyAddress) && (AudioObjectGetPropertyData (deviceId, &propertyAddress, 0 , NULL , &thruSize, &thru) == noErr)) {
1201+ lua_pushboolean (L, thru != 0 );
1202+ } else {
1203+ lua_pushnil (L);
1204+ }
1205+
1206+ return 1 ;
1207+ }
1208+
1209+ // / hs.audiodevice:setThru(thru) -> bool
1210+ // / Method
1211+ // / Set the play through (low latency/direct monitoring) state of the audio device
1212+ // /
1213+ // / Parameters:
1214+ // / * thru - A boolean value. True to enable thru, False to disable
1215+ // /
1216+ // / Returns:
1217+ // / * True if thru was set, False if the audio device does not support thru
1218+ // /
1219+ // / Notes:
1220+ // / * This method only works on devices that have hardware support (often microphones with a built-in headphone jack)
1221+ // / * This setting corresponds to the "Thru" setting in Audio MIDI Setup
1222+ static int audiodevice_setThru (lua_State* L) {
1223+ LuaSkin *skin = [LuaSkin sharedWithState: L];
1224+ [skin checkArgs: LS_TUSERDATA, USERDATA_TAG, LS_TBOOLEAN, LS_TBREAK];
1225+
1226+ audioDeviceUserData *audioDevice = userdataToAudioDevice (L, 1 );
1227+ AudioDeviceID deviceId = audioDevice->deviceId ;
1228+ unsigned int scope;
1229+ UInt32 thru = lua_toboolean (L, 2 );
1230+ UInt32 thruSize = sizeof (UInt32);
1231+
1232+ if (isOutputDevice (deviceId)) {
1233+ scope = kAudioObjectPropertyScopeOutput ;
1234+ } else {
1235+ scope = kAudioObjectPropertyScopeInput ;
1236+ }
1237+
1238+ AudioObjectPropertyAddress propertyAddress = {
1239+ kAudioDevicePropertyPlayThru ,
1240+ scope,
1241+ kAudioObjectPropertyElementMain
1242+ };
1243+
1244+ if (AudioObjectHasProperty (deviceId, &propertyAddress) && (AudioObjectSetPropertyData (deviceId, &propertyAddress, 0 , NULL , thruSize, &thru) == noErr)) {
1245+ lua_pushboolean (L, TRUE );
1246+ } else {
1247+ lua_pushboolean (L, FALSE );
1248+ }
1249+
1250+ return 1 ;
1251+ }
1252+
11651253// / hs.audiodevice:isOutputDevice() -> boolean
11661254// / Method
11671255// / Determines if an audio device is an output device
@@ -1900,6 +1988,8 @@ static int datasource_eq(lua_State* L) {
19001988 {" setVolume" , audiodevice_setvolume},
19011989 {" balance" , audiodevice_balance},
19021990 {" setBalance" , audiodevice_setbalance},
1991+ {" thru" , audiodevice_thru},
1992+ {" setThru" , audiodevice_setThru},
19031993 {" setInputVolume" , audiodevice_setInputVolume},
19041994 {" setOutputVolume" , audiodevice_setOutputVolume},
19051995 {" muted" , audiodevice_muted},
0 commit comments