Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐞 ChannelID.Parameters["fx.start"] not always a LogNormal #142

Open
1 task done
chr15m opened this issue May 12, 2023 · 5 comments
Open
1 task done

🐞 ChannelID.Parameters["fx.start"] not always a LogNormal #142

chr15m opened this issue May 12, 2023 · 5 comments
Assignees
Labels
bug Something isn't working channel-general Properties affecting all channel types events Low-level API

Comments

@chr15m
Copy link

chr15m commented May 12, 2023

Describe the issue

$ python
Python 3.7.9 (default, Feb 28 2023, 14:53:52) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyflp
>>> project = pyflp.parse("2step1.flp")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/pyflp/__init__.py", line 168, in parse
    events.append(event_type(id, value))
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/pyflp/_events.py", line 438, in __init__
    self._struct = self.STRUCT.parse(data, len=len(self._data))
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/construct/core.py", line 288, in parse
    return self.parse_stream(io.BytesIO(data), **contextkw)
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/construct/core.py", line 300, in parse_stream
    return self._parsereport(stream, context, "(parsing)")
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/construct/core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/construct/core.py", line 2120, in _parse
    subobj = sc._parsereport(stream, context, path)
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/construct/core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/construct/core.py", line 2653, in _parse
    return self.subcon._parsereport(stream, context, path)
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/construct/core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/construct/core.py", line 3739, in _parse
    obj = sc._parsereport(stream, context, path)
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/construct/core.py", line 312, in _parsereport
    obj = self._parse(stream, context, path)
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/construct/core.py", line 704, in _parse
    return self._decode(obj, context, path)
  File "/home/chrism/dev/fakeboy.mapp/.direnv/python-3.7.9/lib/python3.7/site-packages/pyflp/_descriptors.py", line 329, in _decode
    raise ValueError(f"Not a LogNormal, 2nd int must be 63; not {obj[1]}")
ValueError: Not a LogNormal, 2nd int must be 63; not 0

Here is the file I tried to load:
2step1.flp.zip

Thank you!

What version of PyFLP are you using?

2.1.0

Code of Conduct

  • I agree to follow this project's Code of Conduct
@chr15m chr15m added the bug Something isn't working label May 12, 2023
@demberto demberto self-assigned this May 12, 2023
@demberto demberto added channel-general Properties affecting all channel types events Low-level API labels May 12, 2023
@demberto demberto changed the title 🐞 ValueError: Not a LogNormal, 2nd int must be 63; not 0 🐞 ChannelID.Parameters["fx.start"] not always a LogNormal May 12, 2023
@demberto
Copy link
Owner

It seems ChannelID.Parameters["fx.start"] used an int instead of the (now) LogNormal / float representation.
While a fix for this is simple, it will be a downgrade for projects and presets saved with newer versions of FL Studio.

I need to find a better solution to such issues.

In the meantime, you can fix this by changing this line

"fx.start" / c.Optional(LogNormal(c.Int16ul[2], (0, 61440))), # 137

to

"fx.start" / c.Optional(c.Int32ul),  # 137

If you are familiar with git and Python, I recommend that you fork PyFLP, clone it locally, make the edits and install it in your environment, instead of changing this manually in your existing installation.

@demberto demberto added this to the 2.1.1 milestone May 12, 2023
@chr15m
Copy link
Author

chr15m commented May 12, 2023

Thank you, will try it.

@chr15m
Copy link
Author

chr15m commented May 13, 2023

Could you wrap it in a try and catch the ValueError and then run the second one?

@demberto
Copy link
Owner

Could you wrap it in a try and catch the ValueError and then run the second one?

Nah it won't work that way. Its not the correct place to do it.

@demberto demberto modified the milestones: 2.1.1, 2.1.2 May 24, 2023
@demberto demberto removed this from the 2.1.2 milestone Jun 11, 2023
@chr15m
Copy link
Author

chr15m commented Sep 21, 2023

I found a truly hacky solution for this, but maybe it can inspire something on your end. The following code monkey-patches a new version of STRUCT with the one commented out field changed.

try:
    project = pyflp.parse(flpfile)
except ValueError:
    flp_monkeypatch_pyflp()
    project = pyflp.parse(flpfile)

def flp_monkeypatch_pyflp():
    from pyflp.channel import StdEnum, _DelayFlags, ArpDirection, DeclickMode, List2Tuple, LinearMusical, StretchMode, Log2, LogNormal
    pyflp.channel.ParametersEvent.STRUCT = c.Struct(
        "_u1" / c.Optional(c.Bytes(9)),  # 9
        "fx.remove_dc" / c.Optional(c.Flag),  # 10
        "delay.flags" / c.Optional(StdEnum[_DelayFlags](c.Int8ul)),  # 11
        "keyboard.main_pitch" / c.Optional(c.Flag),  # 12
        "_u2" / c.Optional(c.Bytes(28)),  # 40
        "arp.direction" / c.Optional(StdEnum[ArpDirection](c.Int32ul)),  # 44
        "arp.range" / c.Optional(c.Int32ul),  # 48
        "arp.chord" / c.Optional(c.Int32ul),  # 52
        "arp.time" / c.Optional(c.Float32l),  # 56
        "arp.gate" / c.Optional(c.Float32l),  # 60
        "arp.slide" / c.Optional(c.Flag),  # 61
        "_u3" / c.Optional(c.Bytes(1)),  # 62
        "time.full_porta" / c.Optional(c.Flag),  # 63
        "keyboard.add_root" / c.Optional(c.Flag),  # 64
        "time.gate" / c.Optional(c.Int16ul),  # 66
        "_u4" / c.Optional(c.Bytes(2)),  # 68
        "keyboard.key_region" / c.Optional(List2Tuple(c.Int32ul[2])),  # 76
        "_u5" / c.Optional(c.Bytes(4)),  # 80
        "fx.normalize" / c.Optional(c.Flag),  # 81
        "fx.inverted" / c.Optional(c.Flag),  # 82
        "_u6" / c.Optional(c.Bytes(1)),  # 83
        "content.declick_mode" / c.Optional(StdEnum[DeclickMode](c.Int8ul)),  # 84
        "fx.crossfade" / c.Optional(c.Int32ul),  # 88
        "fx.trim" / c.Optional(c.Int32ul),  # 92
        "arp.repeat" / c.Optional(c.Int32ul),  # 96; FL 4.5.2+
        "stretching.time" / c.Optional(LinearMusical(c.Int32ul)),  # 100
        "stretching.pitch" / c.Optional(c.Int32sl),  # 104
        "stretching.multiplier" / c.Optional(Log2(c.Int32sl, 10000)),  # 108
        "stretching.mode" / c.Optional(StdEnum[StretchMode](c.Int32sl)),  # 112
        "_u7" / c.Optional(c.Bytes(21)),  # 133
        #"fx.start" / c.Optional(LogNormal(c.Int16ul[2], (0, 61440))),  # 137
        "fx.start" / c.Optional(c.Int32ul),  # 137
        "_u8" / c.Optional(c.Bytes(4)),  # 141
        "fx.length" / c.Optional(LogNormal(c.Int16ul[2], (0, 61440))),  # 145
        "_u9" / c.Optional(c.Bytes(3)),  # 148
        "playback.start_offset" / c.Optional(c.Int32ul),  # 152
        "_u10" / c.Optional(c.Bytes(5)),  # 157
        "fx.fix_trim" / c.Optional(c.Flag),  # 158 (FL 20.8.4 max)
        "_extra" / c.GreedyBytes,  # * 168 as of 20.9.1
    )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working channel-general Properties affecting all channel types events Low-level API
Projects
None yet
Development

No branches or pull requests

2 participants