Batch create a bunch of macros from a text file

Hi all.

I’m looking for a smart and efficient way to automate creating macros from a long list structured like this:

"Preferences_Controls - Value Box/Time Control Mode": "02,119,001",
"Preferences_MediaBay - Scan Folders only when MediaBay is open": "02,119,002",
"Preferences_MediaBay - Scan unknown File Types": "02,119,003", 

For example, from the first line:

"Preferences_Controls - Value Box/Time Control Mode": "02,119,001",

I want to generate a macro like this:

Title (added Cubase as prefix): "Cubase Preferences_Controls - Value Box/Time Control Mode" Action: Send midi control change for controller 119 with value 001 on channel 02.

My goal is to create one macro per line automatically. I’d love to hear if anyone has an elegant script or method to do this quickly and cleanly.

Thanks,

Johannes

I generally avoid using KM to modify KM code. But I have a question about your requirements. Why aren't you asking for any triggers to be set up with each macro? If you aren't setting up triggers, I don't see the need for macros to be set up at all. (You could have a single macro that processes the list each time it is called.)

Also, since macro names are not unique, (i.e., you can have multiple macros with the same name) do you want the solution to be replacing macros if such a macro already exists? But even worse, you need to explain if you want any macros that CALL these macros to be updated (with the new macro names) when you replace the old macros. I'm not sure if there is a solution for that problem.

1 Like

Great question! I use these macros as building blocks for making much more complex routines, so they will be triggered from other macros

Good call!! It is probably a better idea to make a single subroutine that parses the text file for every function I want to recall? I didn’t think of that. My only concern is how snappy the macros would be when KM has to parse the text file (which is around 250kb) for every command.

At 50 characters per line, 250,000 bytes would imply 5000 macros. Do you really have that many macros? I would be more worried about the performance of KM with 5000 macros in a single macro group.

Speed can sometimes be a problem, but it's very common for people to worry about speed before they even write their macros. A well-written macro can process text very fast.

1 Like

Your list isn't very friendly, but it appears to be one item per line so we'll start by cleaning it up into tab-separated values which will be much easier to process. Then we'll pass the cleaned-up text to an AppleScript that makes the macros.

This assumes you have a Macro Group called "Cubase Auto" to make the macros in, so make that if needed. Better to make them in a new Group so you can check a few and, if you're happy, move them all into the Group you actually want them in.

Cubase Macro Generater.kmmacros (5.5 KB)

Image

You can easily change that first action for one that reads your text file into the Local_text variable.

Since this is (I assume) a one-off "create a bunch of components" exercise there's no point wasting time on options or error-checking.

But I'd echo @Airy's comments -- this feels like the wrong approach to a problem you haven't (yet) clearly explained. Perhaps a case of "functions for the sake of functions", since it would be quicker -- both in editing and in execution -- to just add these simple actions to whatever macros need them.

1 Like

For example, last week I wrote a complex text-manipulation macro (which calculated the frequency of every character in a file) using native KM actions, and it was very slow (I think 10 seconds) so I rewrote it in Swift (with help from AI :robot:) and I think it took a tenth of a second.

The lesson here is that even if native KM actions are slow, we have tools inside KM to speed them up.

1 Like

Thanks so much, guys! I really appreciate all the help. This thread has been pure gold—I've got everything I need to solve it now. Thanks again!

1 Like