Categories
Coding

Automate Bitwig

The Goal is to create a Polysynth and add a Reverb Effect.

Dependencies

Python

pyautogui

win32gui

Creating the Script

This Script will automate Bitwig to our needs.

# OpenBitwig.py

import pyautogui, subprocess, time, win32gui, win32con

# Set Dos Window Topmost to see it's Output
hwnd = win32gui.GetForegroundWindow()
rect = win32gui.GetWindowRect(hwnd)
x = rect[0]
y = rect[1]
w = rect[2] - x
h = rect[3] - y
win32gui.SetWindowPos(hwnd,win32con.HWND_TOPMOST,x,y,w,h,0)

# Open Bitwig async
subprocess.Popen(r'"C:\Program Files\Bitwig Studio\Bitwig Studio.exe"')

# Wait for 10 Seconds to find the "New Song" Tab
newTabLocation = pyautogui.locateOnScreen('Images/NewTab.png')
elapsedTime = 0
while newTabLocation is None or elapsedTime < 10 * 10:
    newTabLocation = pyautogui.locateOnScreen('Images/NewTab.png')
    elapsedTime += 100
    time.sleep(.1)

# Make Dos Window normal again
win32gui.SetWindowPos(hwnd,win32con.HWND_NOTOPMOST,x,y,w,h,0)
win32gui.SetForegroundWindow(hwnd)

# Click the middle of the Tab Location
pyautogui.click(newTabLocation.left + newTabLocation.width/2, newTabLocation.top + newTabLocation.height/2)

# Find the "Inst 1 Add" Button and click it at Offset(32, 20)
inst1AddButtonLocation = pyautogui.locateOnScreen('Images/Inst1AddButton.png')
pyautogui.click(inst1AddButtonLocation.left + 32, inst1AddButtonLocation.top + 20)

# Wait 1 Second
time.sleep(1)

# Type "polysnyth"
pyautogui.typewrite('polysynth')

# Wait 1 Second
time.sleep(1)

# Press "Key Down" and "Enter"
pyautogui.press('down')
pyautogui.press('enter')

# Wait 1 Second
time.sleep(1)

# Find the "Instrument Polysynth / Record" Button and click it at Offset(125, 14)
instrumnentPolysynthLocation = pyautogui.locateOnScreen('Images/InstrumentPolysynth.png')
pyautogui.click(instrumnentPolysynthLocation.left + 125, instrumnentPolysynthLocation.top + 14)

# Find the "Instrument Polysynth Device Add" Button and click it at Offset(13, 11)
instrumnentPolysynthDeviceAddButtonLocation = pyautogui.locateOnScreen('Images/DeviceAddButton.png')
pyautogui.click(instrumnentPolysynthDeviceAddButtonLocation.left + 13, instrumnentPolysynthDeviceAddButtonLocation.top + 11)

# Type "reverb"
pyautogui.typewrite('reverb')

# Wait 1 Second
time.sleep(1)

# Press "Key Down" and "Enter"
pyautogui.press('down')
pyautogui.press('enter')

The Images

Images/NewTab.png

Images/Inst1AddButton.png

Images/InstrumentPolysynth.png

Images/DeviceAddButton.png

The Result