flpkit 0.8.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flpkit/__init__.py +512 -0
- flpkit/codec.py +317 -0
- flpkit/data/plugins/fruity-parametric-eq-2.json +8 -0
- flpkit/data/plugins/index.json +3 -0
- flpkit/detect.py +83 -0
- flpkit/formats/__init__.py +17 -0
- flpkit/formats/automation.py +189 -0
- flpkit/formats/effects.py +170 -0
- flpkit/formats/levels.py +97 -0
- flpkit/formats/notes.py +219 -0
- flpkit/formats/playlist.py +173 -0
- flpkit/formats/tempo.py +50 -0
- flpkit/py.typed +0 -0
- flpkit-0.8.1.dist-info/METADATA +124 -0
- flpkit-0.8.1.dist-info/RECORD +17 -0
- flpkit-0.8.1.dist-info/WHEEL +4 -0
- flpkit-0.8.1.dist-info/licenses/LICENSE +21 -0
flpkit/formats/tempo.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Tempo: the project's u32 tempo event (156), BPM x 1000 (set 137 -> FL
|
|
2
|
+
reads back 137000). FL expresses default tempo by omission; when the event is
|
|
3
|
+
absent it is APPENDED at the end of the stream (end-of-stream wins by
|
|
4
|
+
sequential application - live-verified; mid-stream splices load-but-ignore or
|
|
5
|
+
reject depending on position).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from collections.abc import Sequence
|
|
11
|
+
|
|
12
|
+
from flpkit.codec import FlpError, SpliceSite, Stream, Target, verify_identical
|
|
13
|
+
|
|
14
|
+
EVENT_TEMPO = 156 # u32 payload, BPM x 1000
|
|
15
|
+
EVENT_TEMPO_COARSE = 66 # legacy u16 whole BPM (pre-156 files); 156 wins
|
|
16
|
+
EVENT_TEMPO_FINE = 93 # legacy u16 milli-BPM fraction added to coarse
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TempoFormat:
|
|
20
|
+
name = "tempo"
|
|
21
|
+
event_id = EVENT_TEMPO
|
|
22
|
+
frame = None
|
|
23
|
+
|
|
24
|
+
def locate(self, stream: Stream, target: Target) -> SpliceSite:
|
|
25
|
+
"""The first tempo event, else the end-of-stream append point."""
|
|
26
|
+
prev_end = 0
|
|
27
|
+
for event_id, off, size in stream:
|
|
28
|
+
head = prev_end
|
|
29
|
+
prev_end = off + size
|
|
30
|
+
if event_id == EVENT_TEMPO and size == 4:
|
|
31
|
+
return SpliceSite(head, off + size, bytes(stream[off : off + size]))
|
|
32
|
+
return SpliceSite(len(stream), len(stream), None)
|
|
33
|
+
|
|
34
|
+
def encode(self, data: Sequence[float], ppq: int) -> bytes:
|
|
35
|
+
if len(data) != 1:
|
|
36
|
+
raise FlpError(f"a project has exactly one tempo, got {len(data)}")
|
|
37
|
+
(bpm,) = data
|
|
38
|
+
if not 10 <= bpm <= 999:
|
|
39
|
+
raise FlpError(f"tempo {bpm} out of range (10-999 BPM)")
|
|
40
|
+
return round(bpm * 1000).to_bytes(4, "little")
|
|
41
|
+
|
|
42
|
+
def decode(self, blob: bytes, ppq: int) -> list[float]:
|
|
43
|
+
if not blob:
|
|
44
|
+
return []
|
|
45
|
+
if len(blob) != 4:
|
|
46
|
+
raise FlpError(f"tempo payload has {len(blob)} bytes, expected 4")
|
|
47
|
+
return [int.from_bytes(blob, "little") / 1000]
|
|
48
|
+
|
|
49
|
+
def verify(self, sent: Sequence[float], readback: Sequence[float]) -> None:
|
|
50
|
+
verify_identical(sent, readback, "the project tempo")
|
flpkit/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: flpkit
|
|
3
|
+
Version: 0.8.1
|
|
4
|
+
Summary: Read and write FL Studio .flp project files - a small, dependency-free library for the undocumented FLP format, with self-verifying raw-surgery writers
|
|
5
|
+
Project-URL: Homepage, https://github.com/clarkipeng/flpkit
|
|
6
|
+
Project-URL: Repository, https://github.com/clarkipeng/flpkit
|
|
7
|
+
Project-URL: Issues, https://github.com/clarkipeng/flpkit/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/clarkipeng/flpkit/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Origami Research
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: daw,fl-studio,flp,midi,music
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
24
|
+
Requires-Python: >=3.11
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# flpkit
|
|
28
|
+
|
|
29
|
+
Read and write FL Studio `.flp` project files - without FL Studio, without dependencies.
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
import flpkit
|
|
33
|
+
|
|
34
|
+
project = flpkit.read(path) # ppq, tempo, channels (names + levels + automation), notes, playlist
|
|
35
|
+
flpkit.set_tempo(path, 128.5) # returns the tempo the SAVED file contains
|
|
36
|
+
flpkit.write_notes(
|
|
37
|
+
path,
|
|
38
|
+
[flpkit.NoteSpec(key=60, start=0, length=1)], # beats; velocity/pan 0..1
|
|
39
|
+
pattern=1, channel=0, mode="merge",
|
|
40
|
+
) # returns the notes read back from the saved file
|
|
41
|
+
flpkit.set_channel_levels(path, 0, volume=0.8, pan=-0.25)
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Why this exists
|
|
45
|
+
|
|
46
|
+
The FLP format is proprietary and undocumented.
|
|
47
|
+
The existing reverse-engineered library (pyflp, GPL) has a broad *parser*, but its *serializer* rewrites bytes it shouldn't - we observed it write a wrong channel count into the file header and mangle a UTF-16 text event, producing files that parsers read back happily and **real FL Studio refuses to open**.
|
|
48
|
+
|
|
49
|
+
flpkit takes the opposite approach for writing: **raw byte surgery**.
|
|
50
|
+
A write patches or appends exactly the bytes that express the change and never reserializes the file, so everything the library does not model survives untouched.
|
|
51
|
+
Every writer then **verifies itself**: it re-reads the saved file and field-matches the result against what was sent, raising `FlpError` instead of returning hope.
|
|
52
|
+
|
|
53
|
+
## What it reads
|
|
54
|
+
|
|
55
|
+
- PPQ and tempo, including the legacy pre-`156` coarse/fine word pair
|
|
56
|
+
- Channels with display names (user rename → legacy name → plugin internal name) and mix levels across four format generations (`Levels` 219, word events, byte events)
|
|
57
|
+
- Notes per pattern and channel (the 24-byte packed record), with correct attribution for the implicit channel 0 and pre-pattern note blobs that stock FL files contain
|
|
58
|
+
- UTF-16/Latin-1 text switching keyed off the file's `FLVersion`
|
|
59
|
+
- Playlist items per arrangement (pattern/audio clips: position, length, track, group), with the record stride DETECTED per blob - FL grew the record from 32 to 60 to 80 to 88 bytes across eras, and the constant `pattern_base` signature identifies the true size instead of a hardcoded list
|
|
60
|
+
- Automation clips: each type-5 channel's points (position in beats from clip start, value 0..1, tension), decoded from the delta-encoded f64 records and verified point-identical to pyflp across 1,100 real blobs
|
|
61
|
+
|
|
62
|
+
## What it writes
|
|
63
|
+
|
|
64
|
+
- `set_tempo` - patches the tempo event in place, or appends one when the file omits it (FL expresses default tempo by omission; end-of-stream append is the placement real FL accepts)
|
|
65
|
+
- `write_notes` - splices a pattern's notes blob; `mode="replace"` is scoped to the target channel (a pattern's blob holds *every* channel's notes - naive replacement destroys other channels' work)
|
|
66
|
+
- `set_channel_levels` - patches pan/volume/pitch int32s inside the channel's `Levels` event; refuses legacy files rather than writing guessed units
|
|
67
|
+
- `write_playlist` - splices pattern clips into an arrangement's playlist event; every new record is built from the first EXISTING record as a byte template (so the era-specific tail carries FL's own defaults), kept position-sorted the way FL writes them. Live-verified: FL Studio 2026 loads the written clips (song length grows to match) and its OWN re-save round-trips them byte-identically
|
|
68
|
+
- `write_automation` - replaces the points inside an EXISTING automation channel's blob; the 17-byte header and the opaque era trailer are carried verbatim, absolute positions convert back to FL's stored x-deltas, and each point's opaque 4-byte tail rides along.
|
|
69
|
+
Feeding a channel's decoded points straight back is readback-identical; it is byte-identical for FL-authored blobs in corpus tests.
|
|
70
|
+
Creating a NEW clip is out of scope until the link bytes are decoded - a non-automation channel or a missing blob is an error, not an invitation to fabricate
|
|
71
|
+
- `add_effect` and `effects_at` - splice and read captured mixer-effect references while preserving plugin state as opaque data
|
|
72
|
+
|
|
73
|
+
## One engine, formats as data (0.6.0)
|
|
74
|
+
|
|
75
|
+
Every writer and element reader above flows through ONE generic engine, `flpkit.codec`:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from flpkit import codec
|
|
79
|
+
from flpkit.formats import NotesFormat
|
|
80
|
+
|
|
81
|
+
notes = codec.read(path, NotesFormat(), codec.Target(pattern=1, channel=0))
|
|
82
|
+
codec.patch(path, NotesFormat(), codec.Target(pattern=1, channel=0), notes, mode="merge")
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
A `Format` (see `flpkit/formats/`) states one `.flp` element - `locate`, `encode`, `decode`, `verify` - and the engine does the rest: splice, chunk-length fixing, and verify-by-readback live in `codec.patch`, once.
|
|
86
|
+
Reading `formats/notes.py` plus `codec.py` tells you everything about how notes work; the same goes for playlist, automation, levels, tempo, and effects.
|
|
87
|
+
The public functions (`write_notes`, `set_tempo`, ...) are thin shims over `codec.patch`, and `tests/test_differential.py` proves the codec writes byte-identical output to the pre-0.6.0 hand-rolled writers.
|
|
88
|
+
|
|
89
|
+
## Detect, don't assume
|
|
90
|
+
|
|
91
|
+
Format constants are DETECTED from the file itself wherever the data carries an invariant, with hardcoded values only as logged fallbacks:
|
|
92
|
+
|
|
93
|
+
- The playlist record stride is detected per blob (the constant `pattern_base` signature), never taken from a version table.
|
|
94
|
+
- The note-flags word is templated from the target file's own notes; the corpus-surveyed `0x4000` covers files with none.
|
|
95
|
+
- New playlist records inherit their cut-window bytes from an existing record; existing era-specific windows remain opaque.
|
|
96
|
+
- Event-size overrides (event 172 is one byte on FL 2026, not the classic four) are an `event_size_overrides` argument on every public function, so a capability profile can supply a measured table for other FL versions; the built-in FL-2026 table is the once-logged fallback.
|
|
97
|
+
|
|
98
|
+
## How it was verified
|
|
99
|
+
|
|
100
|
+
Every byte-level fact in the source carries its evidence in a comment.
|
|
101
|
+
The facts come from two directions:
|
|
102
|
+
|
|
103
|
+
1. **Differential reading** against pyflp across 164 FL-authored projects (dev-only oracle; flpkit ships with zero dependencies and no GPL code).
|
|
104
|
+
2. **Live FL Studio**: files written by flpkit are opened by real FL Studio 2026 (macOS) and read back over a control connection - tempo, note, and level writes are all confirmed by FL itself, not just by our own parser. The live harness lives in the parent project, [fl-studio-mcp](https://github.com/origami-research/fl-studio-mcp).
|
|
105
|
+
|
|
106
|
+
One example of why the live half matters: a note-record flags field of `0` parses fine everywhere, but every note FL itself writes carries `0x4000` (surveyed: 24,435 records across FL's bundled projects, not one with `0`).
|
|
107
|
+
|
|
108
|
+
## Scope, honestly
|
|
109
|
+
|
|
110
|
+
flpkit models what a composition agent needs: tempo, channels, levels, notes, and captured mixer-effect references.
|
|
111
|
+
It does not decode plugin state or the mixer graph: plugin tuples are captured and spliced as opaque data, while `read()` does not expose a mixer graph. Playlist reading landed in 0.2.0, automation-clip reading in 0.3.0, playlist writing in 0.4.0 (FL-2026 live-verified), automation-point writing in 0.5.0 (readback-identical; byte-identical for FL-authored corpus blobs; live FL round-trip pending).
|
|
112
|
+
Automation clip CREATION (a new curve on a new target) stays out until the target-link bytes are decoded by live minimal-pair experiments.
|
|
113
|
+
|
|
114
|
+
## Captured plugin references
|
|
115
|
+
|
|
116
|
+
Plugin references live in `src/flpkit/data/plugins/`. The index maps a plugin name to one JSON record. Each record has `name`, `fl_build`, `kind`, `chunk_hex`, `sha256`, and `captured_on`. Capture pipelines should write that record from an FL-authored plugin tuple, hash the decoded `chunk_hex`, and add its name to the index. flpkit validates the hash before it splices the opaque tuple.
|
|
117
|
+
|
|
118
|
+
## Bring your own note type
|
|
119
|
+
|
|
120
|
+
`write_notes` accepts any object with `key` (MIDI int), `start`/`length` (beats), `velocity`/`pan` (0..1) attributes - `NoteSpec` is provided for convenience, but a pydantic model or your own dataclass works as-is.
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
MIT.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
flpkit/__init__.py,sha256=d9cWjbmTPtBg1KdVfi6M6LuAiHgiLpNJqtgpFF2R_rc,19286
|
|
2
|
+
flpkit/codec.py,sha256=ZFdLTOKyuoPlPzmOFzFJAAVLhKzL67g1nixG_gNz6Go,13221
|
|
3
|
+
flpkit/detect.py,sha256=wDZP5zkdJsS2eq1k5tagukuYg0HvxdBgChrvimu2h04,3592
|
|
4
|
+
flpkit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
flpkit/data/plugins/fruity-parametric-eq-2.json,sha256=Jg5PpGmqpzqkRHJ7LajJB0acjfCoS9XtQLcJydYc11A,1262
|
|
6
|
+
flpkit/data/plugins/index.json,sha256=GCmx2oywTnW32IYzGAVIVWQID8VKzjjUfpIPNluD-iQ,62
|
|
7
|
+
flpkit/formats/__init__.py,sha256=Sen5Z51ZKy0z_zjthO1Bvz2xmIMhznPY89nANJ7KoRw,856
|
|
8
|
+
flpkit/formats/automation.py,sha256=cenWOkyGhqOqJgTdv01rn5qSDv1Pqn-H8-O_RDcxCQk,8053
|
|
9
|
+
flpkit/formats/effects.py,sha256=0dx65ypzJa2aeMWAcdddO_2cWDrydt9MwDQG2oy8L-o,6653
|
|
10
|
+
flpkit/formats/levels.py,sha256=Nwz3USwy_Pw7WZfVmyo14okgJIpH7xP1KVJvy8KJJg4,3696
|
|
11
|
+
flpkit/formats/notes.py,sha256=i8Vfp-LMk0-qShMXv0Iq52k2X27zrm0cM8U6vCPfYos,9575
|
|
12
|
+
flpkit/formats/playlist.py,sha256=JWBwNp7QtJf-zPg8J8SRtfAq38Xz1_RRtwMIC_W9Cn4,7451
|
|
13
|
+
flpkit/formats/tempo.py,sha256=hSyMa63K2JlexZcWJghIvheRKDvFxHJkY0Rwjndsv2U,1989
|
|
14
|
+
flpkit-0.8.1.dist-info/METADATA,sha256=ssiE-fM5UUh2vcmtbblPKfIdJYkGjar9DsWO0-3obHE,9173
|
|
15
|
+
flpkit-0.8.1.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
|
|
16
|
+
flpkit-0.8.1.dist-info/licenses/LICENSE,sha256=eNlwsjbmP3ED8MlfNRV1y9aZhE5Js2SOJIlVazm-6qU,1073
|
|
17
|
+
flpkit-0.8.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Origami Research
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|