No internet connection
  1. Home
  2. How to

How to make advanced automation task routing the Output on multiple MIDI tracks in Cubase

By Jesper Ankarfeldt @JesperA2019-10-28 19:31:54.543Z2019-10-28 19:51:41.907Z

Answer in OP.

I've made a detailed video going through the code and how I approach creating such a script (20 min). It will be relevant if you're new to scripting and wanna understand it better. The script can of course be adapted to lots of applications:
https://youtu.be/asfMJhA1aTE

This is the finished code from the video. It will make sure that the action is only performed when it's a MIDI track.

var app = sf.ui.nuendo.exists ? sf.ui.nuendo : sf.ui.cubase;
var cubendo = app.title.value;

var midiOutput = 'IAC Driver toIcon' // put the name of your desired MIDI Output
sf.clipboard.setText({ text: midiOutput })

app.appActivateMainWindow();

if (!app.getWindowWithTitleStartingWith('Channel Settings').exists) {
    sf.ui.cubendo.performAction({
        categoryName: "Edit",
        actionName: "Edit Channel Settings",
    });
    sf.wait({ intervalMs: 50 })
}

for (var i = 0; i < 6; i++) { // Put the Amount of MIDI outputs you wanna route

    var isMidiTrack = app.getWindowWithTitleStartingWith('Channel Settings').title.value.match(']') == null;
    var isNotFolder = app.getMenuItem('Project', 'Track Versions', 'New Version').isEnabled

    if (isMidiTrack && isNotFolder) {
        app.getWindowWithTitleStartingWith(cubendo).mouseClickElement({ relativePosition: { x: 50, y: 375 } })
        sf.keyboard.press({ keys: 'cmd+v,enter' })
    }
    else i = i - 1

    sf.ui.cubendo.performAction({
        categoryName: "Project",
        actionName: "Select Track: Next",
    });
    sf.wait({ intervalMs: 1000 })
}

A simplified version of the script (runs faster) but doesn't check what type of track it's on. Only use that if you only have midi tracks after each other:

var app = sf.ui.nuendo.exists ? sf.ui.nuendo : sf.ui.cubase;
var cubendo = app.title.value;

var midiOutput = 'IAC Driver toIcon' // put the name of your desired MIDI Output
sf.clipboard.setText({ text: midiOutput })

app.appActivateMainWindow();

for (var i = 0; i < 6; i++) { // Put the Amount of MIDI outputs you wanna route

        app.getWindowWithTitleStartingWith(cubendo).mouseClickElement({ relativePosition: { x: 50, y: 375 } })
        sf.keyboard.press({ keys: 'cmd+v,enter' })

        sf.ui.cubendo.performAction({
        categoryName: "Project",
        actionName: "Select Track: Next",
    });
    sf.wait({ intervalMs: 50 })
}

.
(afterwards I realized you can do this another way internally in Cubase, but it doesn't make these scripts less valid as a resource)

Solved in post #4, click to view
  • 2 replies
  1. In reply toJesperA:

    Answer in OP

    ReplySolution
    1. In reply toJesperA:

      As experienced in the video I had to add a delay (sf.wait) in order for the script to successfully read when it was a folder. Turns out it's probably because Cubase/Nuendo doesn't update its Menus more then once a second.

      So instead of checking the menu you can just check if the Channel Settings window name changes, cause if it doesn't, you know that it's a folder track. So the script will look like this instead:

      var app = sf.ui.nuendo.exists ? sf.ui.nuendo : sf.ui.cubase;
      var version = app.shortVersionString;
      var cubendo = app.title.value;
      
      var midiOutput = 'IAC Driver to'
      sf.clipboard.setText({ text: midiOutput })
      
      app.appActivateMainWindow();
      
      if (!app.getWindowWithTitleStartingWith('Channel Settings').exists) {
          sf.ui.cubendo.performAction({
              categoryName: "Edit",
              actionName: "Edit Channel Settings",
          });
          sf.wait({ intervalMs: 50 })
      }
      
      var oldName = ''
      
      for (var i = 0; i < 3; i++) {
          var isMidiTrack = app.getWindowWithTitleStartingWith('Channel Settings').title.value.match(']') == null;
      
          var isNotFolder = false
          var newName = app.getWindowWithTitleStartingWith('Channel Settings').title.value;
          if (oldName != newName) {
              isNotFolder = true
              oldName = newName
          }
      
          if (isMidiTrack && isNotFolder) {
              app.getWindowWithTitleStartingWith(cubendo).mouseClickElement({ relativePosition: { x: 50, y: 375 } })
              sf.keyboard.press({ keys: 'cmd+v,enter' })
          }
          else i = i - 1
      
          sf.ui.cubendo.performAction({
              categoryName: "Project",
              actionName: "Select Track: Next",
          });
          sf.wait({ intervalMs: 50 })
      }
      
      1. Progress
      2. @JesperA closed this topic 2019-10-28 19:32:13.950Z.
      3. @chrscheuer reopened this topic 2019-10-29 09:47:50.375Z.