Kara-Moon Forum
April 25, 2024, 02:12:56 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: You can go back to the main site here: Kara-Moon site
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Some plugin musings  (Read 6306 times)
sciurius
Sr. Member
****
Posts: 443



« on: December 29, 2018, 08:19:43 PM »

Writing plugins is, indeed, very easy, especially when using the excellent pluginUtils.py.

Some findings...

mma -o shows file names of mma files, but not the names of plugin files.

The ref docs mentions track_run as entry point. The plugin guide mentions trackRun.

regplug.py says it calculates a sha-1 hash, but is it a sha-256 hash.

IMHO the user should be able to maintain a private library of plugins. E.g., I have ~/lib/mma/plugins/ that (I would want to) contain all my plugins. But MMA refuses to use this. I strongly suggest to augment plugin lookup to use a customizable search path, similar to LibPath. I appreciate the security considerations but to be fair - they only get in the way while providing no real security.

There should be a defined way to get at MMA internals. Without such an API the plugins are basically limited to text preprocessing, and there are many tools much better equipped to handle that.

Anyway, please find attached my first shot at a MMA plugin. The first publicly published MMA plugin, AFAIK Smiley.

* mma-plugin-copyright-1.00.zip (1.92 KB - downloaded 202 times.)
Logged
bvdp
Kara-Moon Master
****
Posts: 1437


WWW
« Reply #1 on: December 29, 2018, 11:56:50 PM »

I'll have a look later at your plugin and at the doc errors ... I don't think this ever ends Smiley

PlugPath should be setable for custom storage locations. I'll have to add "SetPlugPath".

I agree with the security issue and my silly attempt at trying to be cautious. But, I have to assume that some attempt is better than none?Huh

One of the goals of the pluginUtils is to be entry point for accessing other mma internals. Really, it's just a matter of figuring out what is needed to be accessed, adding a jump point and documenting it. I was thinking at some point that it might be nice to actually access the midi data as it was being generated to make mods to that ... but don't know if anyone would ever do that???
Logged

My online life: http://www.mellowood.ca
sciurius
Sr. Member
****
Posts: 443



« Reply #2 on: December 30, 2018, 12:43:17 PM »

Currently my need is to access things like the ChordNotes class and the chordtable. That's fairly trivial.

Would it be possible to run plugins from the data lines, e.g.

1    Am
2    @Expand Cm Repeat=4
6    F7

(And have the line number passed in as an argument)

This would be effectively equal to

1    Am
2    Cm
3    Cm
4    Cm
5    Cm
6    F7

Logged
bvdp
Kara-Moon Master
****
Posts: 1437


WWW
« Reply #3 on: December 30, 2018, 04:45:39 PM »

Currently my need is to access things like the ChordNotes class and the chordtable. That's fairly trivial.

Not sure what you want to do here. But, as you know ... it's really just a matter of doing an appropriate include and there you go ...

Quote
Would it be possible to run plugins from the data lines, e.g.

1    Am
2    @Expand Cm Repeat=4
6    F7

(And have the line number passed in as an argument)

That's pretty trivial, I think. Just parse out the initial line # and the repeat count (use opt2pair() ) and write back 4 four new lines. Shout if you need help with this.
Logged

My online life: http://www.mellowood.ca
sciurius
Sr. Member
****
Posts: 443



« Reply #4 on: December 30, 2018, 07:23:06 PM »

The problem is that it doesn't parse:

2    @Expand Cm Repeat=4

Yields:

Error: <Line 3> <File:hello.mma> Expecting an value after the @ in '@Expand'

It seems MMA wants to parse a chord after the line number.
Logged
bvdp
Kara-Moon Master
****
Posts: 1437


WWW
« Reply #5 on: December 30, 2018, 10:10:40 PM »

Yes, that will not work. As soon as MMA finds a line number it assumes this is a valid chord-data line ... and @expand isn't Smiley

However, if you do:

    @expand 10 Cm repeat=123

you should find success Smiley Your plugin will receive a list like: [10, 'Cm', 'repeat=123']. You can now create a bunch of lists: [ [10, 'Cm'], [11, 'Cm'] ... ], return that to the input stream and all should work.

BTW, I have had a fun afternoon making a little, minor change to the import routine. You can now have a 'plugin' directory in the current dir as well as the other 3 existing locations. This should make collections a bit tidier.

My fun came when I could not get a test plugin to load. The plugin was called "copy" and I kept getting weird errors. Problem was that I'd already loaded a system "copy" module. We now check for that! Don't pick names which are common and probably being used like random, copy, sys, etc.

I'm hoping to upload a new testing release tonight or tomorrow morning.
Logged

My online life: http://www.mellowood.ca
sciurius
Sr. Member
****
Posts: 443



« Reply #6 on: December 30, 2018, 10:31:42 PM »

Good suggestion.

Alternatively a 3rd plugin type could be supported, let's call it a data plugin. If has a method dataRun (cf. trackRun) and added to a (new) list dataPlugs in plugreg.

Module parse.py (line 207 in 16.06b) can then check whether a plugin is specified and run it.
Logged
bvdp
Kara-Moon Master
****
Posts: 1437


WWW
« Reply #7 on: December 31, 2018, 12:28:56 AM »

Good suggestion.

Alternatively a 3rd plugin type could be supported, let's call it a data plugin. If has a method dataRun (cf. trackRun) and added to a (new) list dataPlugs in plugreg.

Module parse.py (line 207 in 16.06b) can then check whether a plugin is specified and run it.

Not sure I understand the problem or trying to solve. Is it that you think you'd like to be able to:

     10 @myplugin Count=123 Cm Dm

And, what would MMA do then? It's already determined that you have a chord line and want to do something with it and it's checking to make sure you have chords, {} solo and [] lyrics. You plugin would have to do something like inserting a chord into the line or something like that? Also, there are macros and subroutines which might be a better choice?
Logged

My online life: http://www.mellowood.ca
sciurius
Sr. Member
****
Posts: 443



« Reply #8 on: December 31, 2018, 09:06:27 AM »

I have this plugin that takes a chord argument (e.g. Cm7), and creates a new chord (e.g. Cm7-1) with a randomly enhanced voicing.

I can call this as:

    @revoice 10 Cm7

which would produce a new input line:

    10 Cm7-1

However, it seems much more inuitive to call it this way:

    10 @revoice Cm7

The treatment would be just like a track plugin. E.g. Bass @Hello discards the current input line and calls the plugin's trackRun method with the track as first argument.
Logged
sciurius
Sr. Member
****
Posts: 443



« Reply #9 on: December 31, 2018, 09:08:42 AM »

My fun came when I could not get a test plugin to load. The plugin was called "copy" and I kept getting weird errors. Problem was that I'd already loaded a system "copy" module. We now check for that! Don't pick names which are common and probably being used like random, copy, sys, etc.

I'm confused... Isn't the @ prefix intended to avoid name clashes?
Logged
bvdp
Kara-Moon Master
****
Posts: 1437


WWW
« Reply #10 on: December 31, 2018, 04:26:17 PM »

The @ avoids MMA name clashes. So, the @copy plugin will not conflict with the MMA native COPY command.

However, the way I've decided to import the code ... well, we have a python package "copy" which contains a module called plugin.py. The problem is that there already is a python package called "copy" and our plugin load barfs. This really had me scratching my head, and the error message from python is quite unhelpful. I now do a check to see if there is a module in memory with the same name and issue a more helpful message.
Logged

My online life: http://www.mellowood.ca
sciurius
Sr. Member
****
Posts: 443



« Reply #11 on: January 01, 2019, 02:26:06 PM »

However, it seems much more inuitive to call it this way:

    10 @revoice Cm7

And, as an added benefit, one can still use the renumber tool to resequence the line numbers.

I've made a POC implementation to accept the above syntax, and it turns out to be really simple (just a couple of lines). Let me know if you are interested.
Logged
bvdp
Kara-Moon Master
****
Posts: 1437


WWW
« Reply #12 on: January 01, 2019, 04:21:01 PM »

However, it seems much more inuitive to call it this way:

    10 @revoice Cm7

And, as an added benefit, one can still use the renumber tool to resequence the line numbers.

I've made a POC implementation to accept the above syntax, and it turns out to be really simple (just a couple of lines). Let me know if you are interested.

I never shut doors to the ideas of others. If you've have a way to accomplish this, send me an email Smiley
Logged

My online life: http://www.mellowood.ca
folderol
Kara-Moon Master
****
Posts: 5308

Who? Me?


WWW
« Reply #13 on: January 02, 2019, 08:49:32 PM »

Just wanted to say this topic has seen more activity lately than it ever has before wOO

Now, if we can just re-animate some of the others Wink
Logged

If you have a poem, I have a tune, and we exchange these, we can both have a poem, a tune, and a song.
- Will
bvdp
Kara-Moon Master
****
Posts: 1437


WWW
« Reply #14 on: January 02, 2019, 11:08:36 PM »

I'm assuming the new accounts is now working?
Logged

My online life: http://www.mellowood.ca
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.064 seconds with 19 queries.