Create an empty midi part between locators using key command instead of double click

hello, I would like to automate the creation of empty part to put them in a macro.

My macro would be something like “select the track named xx” + create an empty event on this track between the locators

thanks

Hi,

I’m afraid this is not possible. Project Logical Editor canot Insert data.

Btw, in the title, you are talking about MIDI Part (which is correct, I expect). In the description, you are talking about Event (which doesn’t make sense here).

I don’t use AutoHotKey, but my impression is that it can do stuff like this.

Hi,

Yes, AutoHotKey can do this.

I’m curious. How would you approach something like that with AHK?

Hi,

I don’t know AHK, I’m not a Windows user.

But I can imagine, you can write mouse XY coordinations. So I would Zoom In Vertically to make sure there is only the given track visible in the project. Then I would blindly click to the project window with the expectation/hope there is the correct address visible.

I gave this a shot. It’s not perfect, but it seems to work.
This solution uses a combination of Project Logical Editor, Macros and an AutoHotKey script. Below is the how-to.

Setup

Project Logical Editor

Create this PLE preset:


Show selected Track only - Toggle.xml (6.5 KB)

Macros

Two Macros are required.
image

These macros are each assigned a Key Command. I have assigned them special characters that are not available on any standard keyboard. I will explain further down how to accomplish this.
image

AutoHotKey script

The AHK script will perform the following steps in order:

  1. Activate the Project Window if not already active
  2. Run the “Create New Part #1” macro (see above)
  3. Move the mouse cursor to a predefined coordinate relative to the active window and double click
  4. Run the “Create New Part #2” macro (see above)
  5. Restore the active window if changed in step 1
  6. Restore the mouse cursor coordinates

There are a few things to keep in mind with this script. The first is the target mouse coordinates. As @Martin.Jirsak mentioned above, since we are “clicking blindly” the script is not 100% fool proof. The mouse coordinate’s origin is the top left of the project window. If for example “Divide Track List” is used and the dividing line is not always in the same place, the mouse click might miss. Similarly if the selected track is we are trying to create a new part on is on the upper or lower track list. There might be other factors that could impact the target coordinates.
The Divide Track List issue can be circumvented by adding the command “Divide Track List” to both macros above. Just keep in mind that the command is a toggling one.

Here is the AHK script:

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance force
#Persistent
CoordMode, Mouse, Window

;*********LEGEND**********
;*	+  = Shift            *
;*	^  = Ctrl             *
;*	!  = Alt              *
;*	#  = Windows key      *
;*************************

;Cubase - Create New Part ******

+^!0::	;The Hotkey (Shift + Alt + Ctrl + 0)
SearchWindow := "Cubase Pro Project"	;Left part of Cubase Project window title
SearchWindowLen := StrLen(SearchWindow)
MouseGetPos, MouseX, MouseY	;Store current mouse coordinates
WinGetTitle, ActiveWindow, A	;Get current active window

;Remove any of the following lines if the
;coresponding modifier key(s) are not used in this Hotkey
KeyWait Shift
KeyWait Alt
KeyWait Control
Sleep 10
;Check if the Project window is
;active and activate it if not
if (SubStr(ActiveWindow, 1, %SearchWindowLen%) == SearchWindow) {
	WindowMatch := 1
} Else {
	WinActivate, %SearchWindow%
	WinWaitActive, %SearchWindow%
}
Sleep 10	;Wait a little...

;Run Cubase Macro "Create New Part #1" (Special character "˪")
Send {U+02EA}
Sleep 50	;Wait a little...

MouseMove, 1100, 380, 0	;Move mouse relative to the active window

;Uncomment the next row to verify target mouse coordinates
;Return

Click, 2	;Double click
Sleep 50	;Wait a little...

;Run Cubase Macro "Create New Part #2" (Special character "˫")
Send {U+02EB}
Sleep 50	;Wait a little...

;Make the previously active window active again
;if that was not the Cubase Project window
if (WindowMatch != 1) {
	WinActivate, %ActiveWindow%
	WinWaitActive, %ActiveWindow%
}

MouseMove, %MouseX%, %MouseY%, 0	;Restore the mouse coordinates
Return

My script uses Shift+Ctrl+Alt+0 but any keyboard key, with or without modifier keys, can be used. If modifier keys used are different than above, the corresponding KeyWait instructions must be altered accordingly.

I have tested this script on Cubase 12 Pro. If you are using a different version of Cubase, make sure that the SearchWindow variable contains a valid search string (left most part of the Cubase Project Window).

This script uses an unusual number of Sleep instructions. I believe they are required due to how Cubase handles keyboard hooks internally.
It is possible that the Sleep durations need adjusting!
These are highly dependent on the specific computer the AHK script is running on. Always err on the side of caution and test thoroughly before running on a live project. If the script appears to not fully complete, it is likely that one of the Sleep instructions need an increased value. (These values are expressed in milliseconds.)

I have added a Return instruction in the middle of the script. This should be un-commented when the script is used for the first time to verify the mouse coordinates. When un-commented, the script will terminate after the mouse cursor has moved to its target “double click position”. It is of course also possible to run a separate script with only the MouseMove instruction to test this out or use the AutoHotKey “Window Spy” feature. Make sure, what ever approach is taken for getting the correct target coordinates on your system, that the Macro “Create New Part #1” has ran first. Once the target mouse position has been adjusted and verified, comment that Return instruction back out.

The special characters

The two Macros are bound to Key Commands using special characters. The benefit is that the script is not consuming regular keyboard keys that could be used by the user directly. It also ensures that modifier keys are not required, which in my tests have proven somewhat slow and unreliable.
To bind the two Macros to these special characters we must temporarily run a second AutoHotKey macro that converts regular keys into these special character.
The below script uses the regular keys 1 and 2 for this purpose.

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance force
#Persistent

1::
Send {U+02EA}	;˪
Return

2::
Send {U+02EB}	;˫
Return

Run this script before binding the two macros to Key Commands and exit the script when completed.

Here are both of the AHK scripts for your convenience:
Create New Part.zip (1.2 KB)


Final thought

None of the above mess would’ve been needed if only there was a command in Cubase already for creating a new part between the locators. Perhaps that is something that is feature request worthy?

By event, I’m sure you mean part.

How about using the "Merge MIDI in Loop " command? If the space between locators is empty, a new empty part will be generated. You’ll have a popup with options, but you can send an “Enter” keypress to perform the operation.

3 Likes

@m.c very convenient shortcut ! Yes I am talking about parts!

I didn’t know about this one thanks. It doesn’t work for multi selected track tho

@mlib thank you so much, are you using AHK v1 or v2 for this ?

I’m using AHK v1.