Kara-Moon Forum

Developers & Technology => Musical MIDI Accompaniment (MMA) => Topic started by: bvdp on July 25, 2019, 06:30:03 PM



Title: SongPath and FilePath variables
Post by: bvdp on July 25, 2019, 06:30:03 PM
I've added 2 variables:

   $SongPath -- the absolute path name of the song (from the command line)
   $FilePath -- abs path of the current file being processed (could be a lib/include file)

These can be handy if you want to have test code in a library file. So, in the lib file:

   bunch of settings
   defgroove SOMETHING

    if eq $SongPath $FilePath
       do test code
    endif


To add to an existing mma just do the following:

  1. to the top macro.py in the list of includes:
      from os import path

   2. Around line 112 add:
     
        elif s == 'FILEPATH':
            if gbl.inpath.fname == 1:
                return "STDIN"
            else:
                return path.abspath(gbl.inpath.fname)

        elif s == 'SONGPATH':
            if gbl.infile == 1:
                return "STDIN"
            else:
                return path.abspath(gbl.infile)
       

thanks sciurius for this. I think that a new mma-19.x is closer than I thought :) At least a devel version :)

   
   


Title: Re: SongPath and FilePath variables
Post by: sciurius on July 25, 2019, 07:01:59 PM
May I suggest to return "-" instead of "STDIN" for standard input?


Title: Re: SongPath and FilePath variables
Post by: bvdp on July 25, 2019, 10:45:00 PM
either works for me. STDIN "could" be a filename ...

If my memory serves, the file '-' is also possible, but probably not. Hard to create :)

So, in that case I think that we'll change all 3 (FILENAME, SONGPATH and FILEPATH) to '-' if it's coming from stdin. Easy :)


Title: Re: SongPath and FilePath variables
Post by: sciurius on July 26, 2019, 07:25:41 AM
A file with name "-" is easy to create, try 'touch ./-'.
If it is really matters, returning an empty string would be best.


Title: Re: SongPath and FilePath variables
Post by: bvdp on July 26, 2019, 04:07:15 PM
Empty is better, I think.


Title: Re: SongPath and FilePath variables
Post by: bvdp on July 27, 2019, 10:03:51 PM
So, that's done :)

Added are $_SongPath, $_FilePath and $_FileName (that was there all along, but not documented). They all return '' if input is coming from stdin.

Also, have added $_Env(..) which returns the value of an env (shell) variable. If the variable doesn't exist or if it has no value a empty string is returned.


Title: Re: SongPath and FilePath variables
Post by: sciurius on July 28, 2019, 09:17:24 AM
Good work! Thanks!

Time to roll out a devel version so we can sync sources for future development?


Title: Re: SongPath and FilePath variables
Post by: bvdp on July 28, 2019, 04:27:23 PM
Yes it is. I just want to integrate you pluginUtils patch! On my list for today.