Preset to Instrument python script

I noticed that many users have created presets (.epr) for their favourite synths…
this is cool (thank you :slight_smile: )
but I’d rather have instrument definitions (.eif), since then I can use these to combine many different instruments into one preset.

so I created a simple python script that would convert a preset (.epr) into an instrument definition (.eif).
(also as a kind of ‘educational’ exercise for me to understand the two formats )

to use:

  • download the above file
    (if you’re not familiar with git, simply click ‘raw’, then use your browser ‘file -> save as’ option)
  • run it using
    python pre2inst.py virus.epr
    obviously substitute virus.epr for the epr file you wish to convert,

there are some limitations…

  • It’s assuming one instrument is in the preset
  • I’ve not tested the sysex at all
  • It’s not minimised, as its for ‘editing’
  • epr files have to be version 2
    (version 1 -> version 2 , import into web editor then download this v2 version)

the EIF file it generates is really intended to be edited after creating to make it a little more ‘sensible’.
in particular, you may want to edit the categories.

the reason for this is presets use a concept of page and control sets which do not match perfectly to the categories of an instrument file…
you can have a two control sets called ‘oscillator’ in a preset as they are 'per page, but categories are unique on instrument definitions. so to ‘resolve’ this, the converter creates a category per page, naming it ‘page name - control set’

you’ll understand this when you see the EIF …it’s easier to see than it is to explain.
to improve ‘you can simply do a search n’ replace on the entire file
(this is important if you rename the category id, you need to also change it on associated parameters)

anyway… not sure how useful it is to others, but I thought I’d share :slight_smile:

(also if your into python, you can see how easy it is for us to manipulate the json files used by electra one - though, im no python expert… Im C++ guy, but in this case python was quick n’ simple)

this file is open source so feel free to copy etc, also if you’d like to make changes send me a pull request via github
(if you don’t know how to do that, just post changes here … but make sure you are using the latest version of the file before changing/posting)

5 Likes

@thetechnobear this is great!

The instrument files were the way we want to go. Meaning building the library of instrument files and then let users to create their own presets. We were pushing on that idea at the very beginning, but as there was not a good editor for instrument files ready yet, users start making presets. We then decided to let it go that way and convert existing public presets into instrument files in future when there is time for it.

You just made a python tool for that :slight_smile:

I have to run out now and will not be around computer till tomorrow eventing. But I will check that out and will get back to you.

Cheers!

1 Like

Nice @thetechnobear !!! Ive been making presets to do something similar. I have empty pages and empty groups which broke your code, so I have an addendum which may need a review.

The following method was altered:

def categoryId(pgId,csId):
    if not controlsets[pgId]:
        return False
    else:
        return pages[pgId]+'-'+controlsets[pgId][csId]

as was this method:

def createParameters(eifdata,eprdata):
    eifdata['parameters'] = []
    parameters = {}


    for i in eprdata['controls']:
        p = { }
        vals = i['values'][0]
        msg  = vals['message']
        pgId = i['pageId']
        csId = i['controlSetId'];
        pid = msg['parameterNumber']

        p['id'] = pid
        p['type'] = i['type']
        p['name'] = i['name']
        if 'min' in msg.keys():
            p['min'] = msg['min']
        if 'max' in msg.keys():
            p['max'] = msg['max']
        if not categoryId(pgId,csId):
            continue
        else:
            p['categoryId'] = categoryId(pgId,csId)
        if 'overlayId' in vals.keys():
            p['overlayId'] = vals['overlayId']
        p['msg'] = msg['type']
        if p['msg'] == 'sysex' :
            p['data'] = msg['data']

        parameters[pid] = p

    for i in parameters.keys():
        eifdata['parameters'].append(parameters[i])

@thetechnobear we may want to put this up on github…

Btw, this was tested with:

  • With presets that have groups
  • With presets that have a group but no controls (this returns nothing for the def)
  • With presets that dont have a group, but have controls (currently returns nothing for the def, this will need to be changed, maybe a random group name?)
  • This doesnt fix the skipped page issue. ill get to that tonight, if no one else does.
1 Like

ok, Ive created a repo for this :slight_smile:

on your tests… are you converting presets created with the web editor?
Id kind of expected all presets to have at least one page.

good point about groups… I’ll create some simple presets and try to convert those.
(I started/tested with Virus preset, so that was used pretty much the whole epr schema :slight_smile: )

Currently only with presets done on the editor, I don’t trust my hand crafted ones yet.
I tested with a couple of the presets that were available and with my crazy ones I created on the editor.
And one that i setup as follows:

  • Korg Drum Preset Page 1 : as is
  • Korg Drum Preset Page 2 : With a group, no control types
  • Korg Drum Preset Page 3 : 4 control types, no group
  • Korg Drum Preset Page 5 : With a group, no control types
  • Korg Drum Preset Page 7 : With a group, 3 control types

ok, created a simple preset without groups and fixed issues.
(from my quick test, there will always be one page, so thats not an issue)

new repo is : https://github.com/TheTechnobear/ElectraOne
(forgot to post link earlier ! )

note: Im removing original code, and pasting a link to the repo.

as previously, this code could probably do with a bit more belt n’ braces, but I’d kind of like to see the failures to learn more about what makes a valid preset, and what is not. ( at least from the editors viewpoint)

if you fancy making changes to the script, feel free… you can see me a PR and I’ll incorporate.
(if later Electra.One what to take it over thats fine by me too… its GPL’d anyway)

1 Like

Sounds good! Thank you and cheers!