Jump to content

Recommended Posts

Posted (edited)

Good day,

I am hoping that I am asking this question correctly?

I have quite a number of functions that, with "minor" exceptions, are very similar, if not identical.

I am wondering if there is a "way-and-means" of amalgamating - that is, "combining" the functions into a single, coherent function?
• I would be assuming that at probable response would be "arrays"?

For example:

Spoiler
; -----------------------------------------------
#include <AutoItConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $iTimeOut = 100
Global $iX = 885, $iY = 222
; -----------------------------------------------
CreatePreset002Scene()
; -----------------------------------------------
Func CreatePreset002Scene()
    ConfigurePreset002AmpSimView()
    ConfigurePreset002FMixerView()
    UpdatePreset002ScenesView($iX, $iY)
    UpdatePreset002SceneProperties($iX, $iY)
EndFunc   ;==>CreatePreset002Scene
; -----------------------------------------------
Func ConfigurePreset002AmpSimView()
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 534, 544, 2, 0)    ; Launch: Preset 002
EndFunc   ;==>ConfigurePreset002AmpSimView
; -----------------------------------------------
Func ConfigurePreset002FMixerView()
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 50, 120, 1, 0)    ; Select: Channel Label [ZMixer]
EndFunc   ;==>ConfigurePreset002FMixerView
; -----------------------------------------------
Func UpdatePreset002ScenesView($iX, $iY)
    Local $hSAC_SCENES = "[CLASS:SAC_SCENES]"
    ; -----------------------------------------------
    WinActivate($hSAC_SCENES)
    ; -----------------------------------------------
    Send("{End}")    ; Select: [End Of List]
    ; -----------------------------------------------
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 188, 118, 1, 0)    ; Select: [New]
    ; -----------------------------------------------
    Sleep($iTimeOut)
    ClipPut("Preset 002")    ; Copy text
    ; -----------------
    Send("{CTRLDOWN}")
    Send("v")    ; Paste text
    Send("{CTRLUP}")
    ; ----------------------
    Send("{ENTER}")    ; Select: [Ok]
EndFunc   ;==>UpdatePreset002ScenesView
; -----------------------------------------------
Func UpdatePreset002SceneProperties($iX, $iY)
    Local $hSAC_SCENEPROPERTIES = "[CLASS:SAC_SCENEPROPERTIES]"
    ; -----------------------------------------------
    Sleep(1500)
    Send("{ENTER}")    ; Select: [OK]
EndFunc   ;==>UpdatePreset002SceneProperties
; -----------------------------------------------

 

...and...

Spoiler
; -----------------------------------------------
#include <AutoItConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $iTimeOut = 100
Global $iX = 885, $iY = 222
; -----------------------------------------------
CreatePreset003Scene()
; -----------------------------------------------
Func CreatePreset003Scene()
    ConfigurePreset003AmpSImView()
    ConfigurePreset003FMixerView()
    UpdatePreset003ScenesView($iX, $iY)
    UpdatePreset003SceneProperties($iX, $iY)
EndFunc   ;==>CreatePreset003Scene
; -----------------------------------------------
Func ConfigurePreset003AmpSImView()
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 534, 564, 2, 0)    ; Launch: Preset 003
EndFunc   ;==>ConfigurePreset003AmpSImView
; -----------------------------------------------
Func ConfigurePreset003FMixerView()
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 50, 120, 1, 0)    ; Select: Channel Label [ZMixer]
EndFunc   ;==>ConfigurePreset003FMixerView
; -----------------------------------------------
Func UpdatePreset003ScenesView($iX, $iY)
    Local $hSAC_SCENES = "[CLASS:SAC_SCENES]"
    ; -----------------------------------------------
    WinActivate($hSAC_SCENES)
    ; -----------------------------------------------
    Send("{End}")    ; Select: [End Of List]
    ; -----------------------------------------------
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 188, 118, 1, 0)    ; Select: [New]
    ; -----------------------------------------------
    Sleep($iTimeOut)
    ClipPut("Preset 003")    ; Copy text
    ; -----------------
    Send("{CTRLDOWN}")
    Send("v")    ; Paste text
    Send("{CTRLUP}")
    ; ----------------------
    Send("{ENTER}")    ; Select: [Ok]
EndFunc   ;==>UpdatePreset003ScenesView
; -----------------------------------------------
Func UpdatePreset003SceneProperties($iX, $iY)
    Local $hSAC_SCENEPROPERTIES = "[CLASS:SAC_SCENEPROPERTIES]"
    ; -----------------------------------------------
    Sleep(1500)
    Send("{ENTER}")    ; Select: [OK]
EndFunc   ;==>UpdatePreset003SceneProperties
; -----------------------------------------------

Whatever is the "move forward"...any assistance in assisting me in getting started would be greatly appreciated!

Thank you all for your time!

 

 

Edited by mr-es335
Remove redundant lines...
Posted (edited)

It could be something like this.

#include <AutoItConstants.au3>

Opt("MustDeclareVars", 1)

Global $iTimeOut = 100

; **** Preset Configuration Array ****
; This is a 2D array holding all the data that changes between presets.
; Column 0: Preset Name - e.g. "Preset 002"
; Column 1: AmpSimView MouseClick Y-coordinate - e.g. 544 or 564
; Column 2: Mouse positioning X-coordinate - e.g. 885
; Column 3: Mouse positioning Y-coordinate - e.g. 222
Global $aPresets[2][4] = [ _
        ["Preset 002", 544, 885, 222], _
        ["Preset 003", 564, 885, 222] _
        ]


CallPresetScene($aPresets[0][0], $aPresets[0][1], $aPresets[0][2], $aPresets[0][3])   ; 🔔  Preset 002

;~ CallPresetScene($aPresets[1][0], $aPresets[1][1], $aPresets[1][2], $aPresets[1][3])  ; 🔔  Preset 003

; ...

; ------------------------------------------------------------------------------
Func CallPresetScene($sPresetName, $iAmpSimY, $iMPosX, $iMPosY)
    ConfigureAmpSimView($sPresetName, $iAmpSimY)
    ConfigureFMixerView()
    UpdateScenesView($sPresetName, $iMPosX, $iMPosY)
    UpdateSceneProperties($iMPosX, $iMPosY)
EndFunc   ;==>CallPresetScene
; ------------------------------------------------------------------------------
Func ConfigureAmpSimView($sPresetName, $iMPosY)
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 534, $iMPosY, 2, 0)
EndFunc   ;==>ConfigureAmpSimView
; ------------------------------------------------------------------------------
Func ConfigureFMixerView()
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 50, 120, 1, 0) ; Select: Channel Label [ZMixer]
EndFunc   ;==>ConfigureFMixerView
; ------------------------------------------------------------------------------
Func UpdateScenesView($sPresetName, $iMPosX, $iMPosY)
    Local $hSAC_SCENES = "[CLASS:SAC_SCENES]"
    WinActivate($hSAC_SCENES)
    Send("{End}") ; Select: [End Of List]
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 188, 118, 1, 0) ; Select: [New]
    Sleep($iTimeOut)
    ClipPut($sPresetName) ; Copy the variable Preset Name
    ; Paste text
    Send("{CTRLDOWN}")
    Send("v")
    Send("{CTRLUP}")
    Send("{ENTER}") ; Select: [Ok]
EndFunc   ;==>UpdateScenesView
; ------------------------------------------------------------------------------
Func UpdateSceneProperties($iMPosX, $iMPosY)
    Local $hSAC_SCENEPROPERTIES = "[CLASS:SAC_SCENEPROPERTIES]"
    Sleep(1500)
    Send("{ENTER}") ; Select: [OK]
EndFunc   ;==>UpdateSceneProperties
; ------------------------------------------------------------------------------

 

Edit:
It reflects the idea more.
Because it has some problems, which stem from your examples.
Like
Func UpdatePreset002SceneProperties($iX, $iY)
Func UpdatePreset003SceneProperties($iX, $iY)
there are parameters $iX, $iY, but you don't use them anywhere in the function

Func UpdatePreset002ScenesView($iX, $iY)
Func UpdatePreset003ScenesView($iX, $iY)
there are parameters $iX, $iY, but you don't use them anywhere in the function

Edited by ioa747

I know that I know nothing

Posted

Good day,

Attempting "...to get my head around the implementation of arrays...", all that i can say for the present is "WOW!..."WOW, WOW!", and, "WOW!, WOW!, WOW!"

Thanks again, ios747 [..to the 14th power!...]...

 

Posted

Another logic, which could be, is to store the Presets or a grouped job in a Section, from an .ini file, (which is also an array) with the format

[Preset 002]
ConfigureAmpSimView=534
ConfigureFMixerView=
UpdateScenesView=Preset 002|885|222
UpdateSceneProperties=885|222

[Preset 003]
ConfigureAmpSimView=564
ConfigureFMixerView=
UpdateScenesView=Preset 003|885|222
UpdateSceneProperties=885|222

[Open Amp]
...
...

and then instead of calling the CallPresetScene() function, change it to one for all, e.g. CallSection()

CallPresetScene($aPresets[0][0], $aPresets[0][1], $aPresets[0][2], $aPresets[0][3]) ; 🔔 Preset 002

; you could call
CallSection("Preset 002")

 

I know that I know nothing

Posted

@mr-es335 You are absolutely right in thinking about arrays! Here is the optimal way to combine similar functions:
Difference Analysis
Between Preset 002 and 003, there are only 2 differences:

  1. Preset number (002 vs 003) - appears in the function name and text
  2. Y mouse click coordinate in ConfigurePresetXXXAmpSimView(): 544 vs 564

Combination solution:

#include <AutoItConstants.au3>
Opt("MustDeclareVars", 1)

Global $iTimeOut = 100
Global $iX = 885, $iY = 222

; Configuration for each preset
Global $aPresetConfig[4][3] = [ _
    ["002", 544], _
    ["003", 564], _
    ["004", 584], _  ; Example of adding new preset
    ["005", 604] _
]

; Run preset 002
CreatePresetScene("002")

; Runpreset 003
CreatePresetScene("003")

Func CreatePresetScene($sPresetNum)
    Local $iYCoord = GetPresetYCoord($sPresetNum)
    If $iYCoord = -1 Then Return SetError(1, 0, 0)

    ConfigureAmpSimView($iYCoord)
    ConfigureFMixerView()
    UpdateScenesView($sPresetNum, $iX, $iY)
    UpdateSceneProperties($iX, $iY)
EndFunc

Func GetPresetYCoord($sPresetNum)
    For $i = 0 To UBound($aPresetConfig) - 1
        If $aPresetConfig[$i][0] = $sPresetNum Then Return $aPresetConfig[$i][1]
    Next
    Return -1
EndFunc

Func ConfigureAmpSimView($iYCoord)
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 534, $iYCoord, 2, 0)
EndFunc

Func ConfigureFMixerView()
    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 50, 120, 1, 0)
EndFunc

Func UpdateScenesView($sPresetNum, $iX, $iY)
    Local $hSAC_SCENES = "[CLASS:SAC_SCENES]"

    WinActivate($hSAC_SCENES)
    Send("{End}")

    Sleep($iTimeOut)
    MouseClick($MOUSE_CLICK_LEFT, 188, 118, 1, 0)

    Sleep($iTimeOut)
    ClipPut("Preset " & $sPresetNum)
    Send("^v")  ; Ctrl+V ngắn gọn hơn
    Send("{ENTER}")
EndFunc

Func UpdateSceneProperties($iX, $iY)
    Local $hSAC_SCENEPROPERTIES = "[CLASS:SAC_SCENEPROPERTIES]"
    Sleep(1500)
    Send("{ENTER}")
EndFunc

Advantages

  1. Adding new presets is easy: Just add 1 line to $aPresetConfig
  2. Compact code: From ~90 lines to ~50 lines
  3. Easy to maintain: Fixing logic only needs to be done in 1 place instead of multiple functions

If there are more different parameters
If the preset has more different coordinates, extend the array:

Global $aPresetConfig[][] = [ _
    ["002", 544, 50, 120], _  ; [preset, yCoord, xMixer, yMixer]
    ["003", 564, 50, 120] _
]

 

Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   1 member

×
×
  • Create New...