stwrap.py 825 B

1234567891011121314
  1. # build a VST3 host state (JUCE XML) for a Soundtoys plugin from a VST2 chunk text taken from an FL project
  2. # usage: stwrap.py template.state her.bin out.state (template = savestate of the same plugin in the trial)
  3. import sys, re, struct
  4. sys.path.insert(0, sys.argv[0].rsplit('/',1)[0])
  5. import jucestate as J
  6. t=open(sys.argv[1],'rb').read(); x=t[8:].decode()
  7. comp=J.dec(re.search("<IComponent>(.*?)</IComponent>",x).group(1))
  8. i=comp.index(b'WIDGET'); hdr=bytearray(comp[:i-4])
  9. her=open(sys.argv[2],'rb').read(); her=her[her.index(b'WIDGET'):]
  10. c=hdr.index(b'CcnK')
  11. new=hdr+struct.pack('>I',len(her))+her
  12. struct.pack_into('>I',new,c+4,len(new)-(c+8))
  13. x=re.sub("<IComponent>(.*?)</IComponent>","<IComponent>"+J.enc(bytes(new))+"</IComponent>",x)
  14. xb=x.encode(); open(sys.argv[3],'wb').write(t[:4]+struct.pack('<I',len(xb))+xb)