Skip to content

Commit

Permalink
Fix ui_example bug
Browse files Browse the repository at this point in the history
  • Loading branch information
SaifAqqad committed Feb 12, 2024
1 parent 64d6c2e commit 323ecce
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions examples/ui_example.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand All @@ -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))
}

/**
Expand Down

0 comments on commit 323ecce

Please sign in to comment.