[SOLVED] Changes when running Midi > Scripts?

MusE is a DAW for Linux with both MIDI and Audio editing. https://muse-sequencer.github.io

Moderators: MattKingUSA, khz, spamatica

spamatica
Established Member
Posts: 573
Joined: Mon Feb 08, 2010 10:38 am
Has thanked: 80 times
Been thanked: 97 times

Re: Changes when running Midi > Scripts?

Post by spamatica »

Tim E. Real wrote: Fri Oct 30, 2020 10:38 pm Wow, MusE is pretty smart, eh?
Yeah!
The scripting/plugin system is really simple but that is also what can make it extremely powerful.
I'm actually quite proud of that addition :)

As you noted, the scripts do not have to be written in python. Instead it simply executes an external program and reads back the output. (I think this was the reason it wasn't called script before. It doesn't have to be scripts. But Python is really the best language to use for writing them. Pretty easy to learn yet incredibly powerful.

As for my use case above, changing velocity of one explicit note, I took the time and wrote that little script now, checked in as ConstantVelocityForNote, complete with a little dialog to select the note.
Incidentally I found that what we call C3 is C4 in some documents I found on the internet, didn't we already go over this? Or is the world so divided that there isn't one right?

For anyone curious, here's a condensed version of the above script, without gui. It requires that you edit the script before using it but sometimes that is a better solution.

Code: Select all

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# MusE external midi processing script
import sys

fileToProcess = open(sys.argv[1],"r")
inputEvents = fileToProcess.readlines()
fileToProcess.close()

selectedNote = 60
newVelocity = 100

outputEvents=[]

#loop through events
for line in inputEvents:
  if line.startswith('NOTE'):
    tag,tick,note,length,velocity = line.split(' ')
    if int(note) == int(selectedNote):
      outputEvents.append("%s %s %s %s %d\n"%(tag,tick,note,length,newVelocity))
    else:
      outputEvents.append(line)
  else:
    outputEvents.append(line)

fileToProcess = open(sys.argv[1],"w")
fileToProcess.writelines(outputEvents)
fileToProcess.close()
Stick it in a file, save it in .config/MusE/MusE/scripts/ and make the script executable.
MusE DAW
Tim E. Real
Established Member
Posts: 660
Joined: Sat Sep 15, 2012 12:36 am
Has thanked: 36 times
Been thanked: 105 times

Re: Changes when running Midi > Scripts?

Post by Tim E. Real »

Thanks!
Wow, MusE is pretty smart, eh?
MusE is smart.
And now MusE is pretty.
Thanks to @kybos.
I suggest we remove python 2 completely. It's obsolete and no longer maintained anyway.
Fine with me. Should be simple to bump up the cmake requirement and update the READMEs.

I made sure the remote feature could run with python 2 because I could do that. Whatever version the user wanted to write code in, they could.
But it was not possible with the built-in scripts because there would need to be two different versions of the scripts,
depending on the installed python version.
kybos
Established Member
Posts: 97
Joined: Wed Oct 23, 2019 5:50 am
Been thanked: 3 times

Re: Changes when running Midi > Scripts?

Post by kybos »

spamatica wrote: Sat Oct 31, 2020 5:59 pm As you noted, the scripts do not have to be written in python. Instead it simply executes an external program and reads back the output. (I think this was the reason it wasn't called script before. It doesn't have to be scripts.
That's right and I was aware of it, but the containing folders are called "scripts", and in the docu/specs it's called midi scripting. So calling the menu Scripts too is the the less confusing variant IMO ;-). "Plugins" was bad also for other reasons, the term is already overused in MusE: Synth/Effect plugins (which is perfectly OK here), "Input plugins" in the MIDI menu... It's not good to call completely different things by the same term inside one application (there are other synonyms, like Addons, Addins, whatever).
As for my use case above, changing velocity of one explicit note, I took the time and wrote that little script now, checked in as ConstantVelocityForNote, complete with a little dialog to select the note.
It doesn't show up in the menu, I guess you forgot to add it to the cmake file ;-).
Incidentally I found that what we call C3 is C4 in some documents I found on the internet, didn't we already go over this? Or is the world so divided that there isn't one right?
There is no real standard, unfortunately. I saw C3, C4 and C5 to represent the middle C. BTW, C5 makes most sense in midi context, as it avoids the negative numbers for the lower Cs, but it's the least usual.
Some DAWs have a user setting to choose the preferred option. We could do that as well, but then we should be careful about hardcoding the values.
spamatica
Established Member
Posts: 573
Joined: Mon Feb 08, 2010 10:38 am
Has thanked: 80 times
Been thanked: 97 times

Re: Changes when running Midi > Scripts?

Post by spamatica »

kybos wrote: Sun Nov 01, 2020 9:50 am
It's not good to call completely different things by the same term inside one application (there are other synonyms, like Addons, Addins, whatever).
Yep yep, I'm perfectly fine with calling it scripts.
It doesn't show up in the menu, I guess you forgot to add it to the cmake file ;-).
Ah, yes, of course I did ;) added it now.
MusE DAW
kybos
Established Member
Posts: 97
Joined: Wed Oct 23, 2019 5:50 am
Been thanked: 3 times

Re: Changes when running Midi > Scripts?

Post by kybos »

oscillator wrote: Fri Oct 30, 2020 7:41 pm
kybos wrote: Thu Oct 29, 2020 9:08 am A simpler alternative could be to offer a refresh function for the Scripts menu, so you could create a new script in the user scripts folder as usual, then refresh the menu and it would be there, without the need for restart.
(If I remember right, the scripts are always loaded from disc on execution, so this would only be necessary for new scripts, not for modified ones.)
I'd love a refresh function.

If the scripts contents are loaded when they execute, I can go for a permanent "test"-script, that I can change in an external texteditor.
There is now a refresh (re-read) function in the scripts menus, so it's possible to add new scripts without restarting.
User avatar
oscillator
Established Member
Posts: 1127
Joined: Sat Jan 17, 2015 6:07 pm
Location: SWEDEN
Has thanked: 725 times
Been thanked: 296 times
Contact:

Re: Changes when running Midi > Scripts?

Post by oscillator »

kybos wrote: Mon Nov 02, 2020 6:28 pm There is now a refresh (re-read) function in the scripts menus, so it's possible to add new scripts without restarting.
Awesome! Thank you @kybos!

MusE DAW running on Debian 11 Testing/XFCE4.
https://oscillator.se/musik

Post Reply