Shrink parts to fit contents? (MIDI)

I’m wondering if anyone has devised a way to shrink (trim) the starts & ends of selected MIDI parts to fit its data, snapping to either the nearest bar or beat on the grid?

I’ve poked around with the Project Logical Editor but haven’t found a way yet. If I recall, Logic Pro had a feature that would more-or-less accomplish this.

The preference Record -> MIDI -> Snap MIDI Parts to Bars does accomplish this, but only while recording. I’m looking for a function that can do this for selected parts arbitrarily. And ideally, with the option to the nearest beat and not the nearest bar.

Isn’t there an “events to parts” option somewhere that would (sort of) do this?

The only the thing I can see would globally delete empty parts, and trim to the start and end of the notes (not beat), which you might not want at all. You probably tried this, but if not, it would be something like this macro, performed with the track in question selected:

open key edit
select all
Locators to selection
close key edit (or project to front)
split loop
PLE: Delete empty parts

edit: I could not find a way to do the operation on the selected track only, but I have a sneaking suspicion I am missing something, maybe having to do with the PLE conditions order.

I found an ‘elegant’ way to do this with one keystroke

In the Project Window, be in the Range tool
Single click on the midi part to place the Range cursor, then

Simple trim though, does not extend and quantize part’s start and end to bars or beats.

You guys are GOOD.

Geez Steve. :laughing:

Question for Steve… on your instructions above for your elegant, easy steps to do a simple trim of a part to fit the midi contents, you had posted an image to show the single keystroke to make that work… but the image being referenced is no longer available. So, for those (like me) who are new to Cubase, we aren’t sure which key to press. Hope you can clarify, and thanks in advance for the help.

Fixed pic. Note this is from Cubase 8, and assumes you have the windowed key editor, and not the Lower Zone set to open by default.

Ok so I worked out a 27-step macro that makes this work with less effort. Anyone want me to post it?

27 steps! Yes please! (should this thread be moved to the Cubase 9 forum?)

So after a bit of trial and error, here’s a 40(?)-step macro. A word of warning: this is for advanced users. It’s getting increasingly convoluted, so use it if you want but I can’t be responsible if you can’t get it to work. :laughing: Seriously, I spent like 5 hours ironing out bugs that kept cropping up. (This is largely because I’ve been needing a trim function like this for years, and it’s something I would use hundreds of times a day, so I wanted to make sure it was polished.) Steinberg, why can’t we get a scriptable UI/project scripts??? Possibilities would be endless…

The reason this is so long is that I tested it in many complex scenarios, and tried to mitigate any undesirable effects or potential bugs. If you would like a breakdown of the reasoning behind all the macro actions, I can make another post detailing that.

What it does in a nutshell:

  • This macro trims a single MIDI part (muted or unmuted, doesn’t matter), padding to the nearest quarter note at the start and end of the selected part, and ensures MIDI CC data that may be on hidden lanes isn’t truncated. The padding is hard-coded into the macro but you can change it to the nearest bar, half-note, etc. by changing the “Set Quantize to 4th” macro event to a different division from the ‘Quantize’ macro actions folder. ie, “Set Quantize to 1/1” will pad by a full bar. Or you can have it use the project’s current quantize setting if you just delete the “Set Quantize to 4th” macro event. That way the macro is more dynamic; maybe sometimes you want to trim to a bar, sometimes to a quarter note, etc.
  • You only need to select a part using the default Object Selection tool (which I use primarily). (The macro uses the Range tool but it will set it back to the Object tool for you at the end of the macro.)

Some caveats - use at your own risk:

  • As steve mentioned, this assumes you’re using the windowed key editor, and not the Lower Zone set to open by default.
  • You MUST have one Visibility Configuration Preset set up, and have the #1 preset selected. It’s easy to set this up in a template file. (This is unavoidable because of how the macro needs to play with track visibility to work, and this was the only way I could get to work reliably, trust me.)
  • The MIDI part must be selected with the Object Selection tool prior to running the macro.
  • Be careful not to run the macro if there are no MIDI parts selected.
  • Likewise, this will produce undesirable results if more than one MIDI part is selected.
  • It doesn’t work properly if you select a region on a track that has lanes visible. Hide the track’s lanes before running the macro.
  • As always, there may still be bugs, so test it in a copy of your project before using it in mission-critical projects.

Step 1)
Make sure your project has at least one Visibility Configuration Preset (set in the top-left of the project window), and the first one (#1) is selected in the project window’s toolbar. Then you’re good to go. You can set up your template to have it, and once it’s in a project, it’s in the project forever and you don’t need to add it again.

Step 2)
Here is the PLE preset. Save it as “Hide All Tracks Except MIDI Tracks”. This needs to be the 2nd event in the macro (as seen above). I’ve attached the xml file for it:

Hide MIDI Tracks With Data.xml.zip (1.12 KB)

Step 3)
If you know how to edit XML files in the Cubase Prefs folder, edit Key Commands.xml and insert this. Otherwise it’s tricky to build the macro in the Key Commands window manually because some of the action names are different in the GUI vs. how they’re stored in the XML file, but you might still be able to figure it out. (Sorry - time consuming I know, but there’s no macro import/export function in Cubase other than importing/exporting your entire set of key commands and all macros at the same time. And it’s hard to make a screen shot of a macro this long).

<item>
   <string name="Name" value="Trim MIDI Region"/>
   <list name="Commands" type="list">
      <item>
         <string name="Category" value="Transport"/>
         <string name="Name" value="Locators to Selection"/>
      </item>
      <item>
         <string name="Category" value="Channel &amp; Track Visibility"/>
         <string name="Name" value="Update Track Visibility Configuration"/>
      </item>
      <item>
         <string name="Category" value="Process Project Logical Editor"/>
         <string name="Name" value="Hide All Tracks Except MIDI Tracks"/>
      </item>
      <item>
         <string name="Category" value="Channel &amp; Track Visibility"/>
         <string name="Name" value="ShowMarked"/>
      </item>
      <item>
         <string name="Category" value="Project"/>
         <string name="Name" value="Select Track: Next"/>
      </item>
      <item>
         <string name="Category" value="Project"/>
         <string name="Name" value="Select Track: Next"/>
      </item>
      <item>
         <string name="Category" value="Project"/>
         <string name="Name" value="Select Track: Next"/>
      </item>
      <item>
         <string name="Category" value="Project"/>
         <string name="Name" value="Select Track: Next"/>
      </item>
      <item>
         <string name="Category" value="Project"/>
         <string name="Name" value="Select Track: Next"/>
      </item>
      <item>
         <string name="Category" value="Project"/>
         <string name="Name" value="Select Track: Next"/>
      </item>
      <item>
         <string name="Category" value="Project"/>
         <string name="Name" value="Select Track: Next"/>
      </item>
      <item>
         <string name="Category" value="Project"/>
         <string name="Name" value="Select Track: Next"/>
      </item>
      <item>
         <string name="Category" value="Project"/>
         <string name="Name" value="Select Track: Next"/>
      </item>
      <item>
         <string name="Category" value="Project"/>
         <string name="Name" value="Select Track: Next"/>
      </item>
      <item>
         <string name="Category" value="Tool"/>
         <string name="Name" value="Range Tool"/>
      </item>
      <item>
         <string name="Category" value="Edit"/>
         <string name="Name" value="Select All on Tracks"/>
      </item>
      <item>
         <string name="Category" value="Transport"/>
         <string name="Name" value="To Left Locator"/>
      </item>
      <item>
         <string name="Category" value="Edit"/>
         <string name="Name" value="Left Selection Side to Cursor"/>
      </item>
      <item>
         <string name="Category" value="Transport"/>
         <string name="Name" value="To Right Locator"/>
      </item>
      <item>
         <string name="Category" value="Edit"/>
         <string name="Name" value="Right Selection Side to Cursor"/>
      </item>
      <item>
         <string name="Category" value="MIDI Quantize"/>
         <string name="Name" value="Set Quantize to 4th"/>
      </item>
      <item>
         <string name="Category" value="Editors"/>
         <string name="Name" value="Open Key Editor in Window"/>
      </item>
      <item>
         <string name="Category" value="MIDI"/>
         <string name="Name" value="Show Used Controllers"/>
      </item>
      <item>
         <string name="Category" value="Edit"/>
         <string name="Name" value="Select All"/>
      </item>
      <item>
         <string name="Category" value="Transport"/>
         <string name="Name" value="Locate Selection"/>
      </item>
      <item>
         <string name="Category" value="Edit"/>
         <string name="Name" value="Open/Close Editor"/>
      </item>
      <item>
         <string name="Category" value="Transport"/>
         <string name="Name" value="Nudge Cursor Left"/>
      </item>
      <item>
         <string name="Category" value="Edit"/>
         <string name="Name" value="Left Selection Side to Cursor"/>
      </item>
      <item>
         <string name="Category" value="Editors"/>
         <string name="Name" value="Open Key Editor in Window"/>
      </item>
      <item>
         <string name="Category" value="Edit"/>
         <string name="Name" value="Select All"/>
      </item>
      <item>
         <string name="Category" value="Transport"/>
         <string name="Name" value="Locate Selection End"/>
      </item>
      <item>
         <string name="Category" value="Edit"/>
         <string name="Name" value="Open/Close Editor"/>
      </item>
      <item>
         <string name="Category" value="Transport"/>
         <string name="Name" value="Nudge Cursor Right"/>
      </item>
      <item>
         <string name="Category" value="Edit"/>
         <string name="Name" value="Right Selection Side to Cursor"/>
      </item>
      <item>
         <string name="Category" value="Tool"/>
         <string name="Name" value="Range Tool"/>
      </item>
      <item>
         <string name="Category" value="Edit"/>
         <string name="Name" value="Crop Range"/>
      </item>
      <item>
         <string name="Category" value="Tool"/>
         <string name="Name" value="Select Tool"/>
      </item>
      <item>
         <string name="Category" value="Edit"/>
         <string name="Name" value="Select in Loop"/>
      </item>
      <item>
         <string name="Category" value="Mixer"/>
         <string name="Name" value="Channel and Rack Configuration 1"/>
      </item>
   </list>
</item>

Thanks for posting- I will check it out as time allows. And I’m with you on wanting more script-like access to Cubase! (Heh, 40 steps. But Cubase does it, and it works, which is sort of amazing in itself.)