diff --git a/examples/ui_example.ahk b/examples/ui_example.ahk index fea7224..6725c28 100644 --- a/examples/ui_example.ahk +++ b/examples/ui_example.ahk @@ -42,40 +42,43 @@ AddControls(vmObj, xPos, yPos) { ; Level Indicator yPos += 30 - objLevel := ui.Add("Progress", "x" xPos " y" yPos " w20 h200 Range-72-20 c0x70C399 Background0x2C3D4D vertical") - voicemeeter.On("levelsUpdated", (*) => objLevel.Value := Max(vmObj.Level*)) + levelIndicator := ui.Add("Progress", "x" xPos " y" yPos " w20 h200 Range-72-20 c0x70C399 Background0x2C3D4D vertical") + ; Bind voicemeeter changes to the UI + voicemeeter.On("levelsUpdated", (*) => levelIndicator.Value := Max(vmObj.Level*)) ; Gain Controls yPos += 220 - objGain := ui.Add("Edit", "x" xPos " y" yPos " w50 ReadOnly") - objUpDn := ui.Add("UpDown", "x" xPos " y" yPos " Range-60-12") - objGain.OnEvent("Change", (*) => vmObj.Gain := Number(objGain.Value)) - objGain.Value := vmObj.Gain + gainControl := ui.Add("Edit", "x" xPos " y" yPos " w50 ReadOnly") + gainUpDn := ui.Add("UpDown", "x" xPos " y" yPos " Range-60-12") + ; Initial state + gainUpDn.Value := vmObj.Gain + ; Bind UI changes to voicemeeter + gainUpDn.OnEvent("Change", (*) => vmObj.Gain := Number(gainUpDn.Value)) + ; Bind voicemeeter changes to the UI + voicemeeter.On("ParametersChanged", (*) => gainUpDn.Value := vmObj.Gain) ; Mute Controls yPos += 30 objMute := ui.Add("CheckBox", "x" xPos " y" yPos, "Mute") + ; Initial state objMute.Value := vmObj.Mute + ; Bind UI changes to voicemeeter objMute.OnEvent("Click", (*) => vmObj.Mute := objMute.Value) - ; Bind voicemeeter changes to the UI - onChanges(*) { - objGain.Value := vmObj.Gain - objMute.Value := vmObj.Mute - } - voicemeeter.On("parametersChanged", onChanges) + voicemeeter.On("ParametersChanged", (*) => objMute.Value := vmObj.Mute) ; Device selector (only for physical strips and buses) if (vmObj.IsPhysical()) { yPos += 30 - deviceDdl := ui.AddDropDownList("x" xPos " y" yPos " w130", []) + deviceDdl := ui.Add("DropDownList", "x" xPos " y" yPos " w130", []) + ; Initial state + RefreshDevices(deviceDdl, vmObj) + ; Bind UI changes to voicemeeter deviceDdl.OnEvent("Change", (*) => vmObj.Device := GetDeviceByDisplayName(deviceDdl.Text)) - ; Bind voicemeeter changes to the UI - voicemeeter.On(VMRConsts.Events.DevicesUpdated, (*) => RefreshDevices(deviceDdl, vmObj)) - voicemeeter.On(VMRConsts.Events.ParametersChanged, (*) => SetTimer(() => deviceDdl.Choose(GetDeviceDisplayName(vmObj.Device)), -1000)) - - RefreshDevices(deviceDdl, vmObj) + voicemeeter.On("DevicesUpdated", (*) => RefreshDevices(deviceDdl, vmObj)) + ; Delay setting the ddl value to avoid getting the wrong device name + voicemeeter.On("ParametersChanged", (*) => SetTimer(() => deviceDdl.Choose(GetDeviceDisplayName(vmObj.Device)), -1000)) } } @@ -85,20 +88,22 @@ AddControls(vmObj, xPos, yPos) { * @param {VMRAudioIO} ioObj */ RefreshDevices(ddl, ioObj) { - global voicemeeter - local i, device, + local device, + ; Get the devices array based on the object type devicesArr := ioObj is VMRStrip ? VMRStrip.Devices : VMRBus.Devices, - deviceNames := [""] ; Add an empty item to remove the selected device + deviceNames := [""] ; Add an empty item to allow removing the selected device - for i, device in devicesArr { + ; Get the display name of every device + for device in devicesArr { deviceNames.Push(GetDeviceDisplayName(device)) } + ; Replace the items in the dropdown list ddl.Delete() ddl.Add(deviceNames) - local dd := ioObj.Device - local currentDevice := GetDeviceDisplayName(dd) - ddl.Choose(currentDevice) + + ; Choose the current selected device + ddl.Choose(GetDeviceDisplayName(ioObj.Device)) } /**