FL Studio Python Scripting
Complete reference for FL Studio's Python API: MIDI controller scripting (14 modules, 427+ functions), piano roll note manipulation, Edison audio editing, and FLP file parsing with PyFLP.
Quick Start
Requirements
- FL Studio 20.8.4+, Python 3.6+
Check API Version
import general
print(f"API Version: {general.getVersion()}")
Script Installation
Place scripts in Shared\Python\User Scripts folder.
Three Scripting Contexts
1. MIDI Controller Scripting
Purpose: Control FL Studio through hardware MIDI controllers and send feedback to devices.
Runs: Continuously while FL Studio is open.
Available modules: transport, mixer, channels, arrangement, patterns, playlist, device, ui, general, plugins, screen, launchMapPages, utils, callbacks
Entry points:
def OnInit():
"""Called when script starts."""
pass
def OnDeInit():
"""Called when script stops."""
pass
def OnMidiMsg(msg):
"""Called for incoming MIDI messages."""
pass
def OnControlChange(msg):
"""Called for CC messages."""
pass
def OnNoteOn(msg):
"""Called for note-on messages."""
pass
def OnRefresh(flags):
"""Called when FL Studio state changes."""
pass
2. Piano Roll Scripting
Purpose: Manipulate notes and markers in the piano roll editor.
Runs: Once when user invokes through Scripts menu.
Available modules: flpianoroll, enveditor
import flpianoroll
score = flpianoroll.score
for note in score.notes:
note.velocity = 0.8 # Set all velocities to 80%
3. Edison Audio Scripting
Purpose: Edit and process audio samples in Edison.
Runs: Once within Edison's context.
Available modules: enveditor
API Module Reference Map
Navigate to the appropriate reference file based on what you need to control.
Read these files ONLY when you need specific API signatures.
Core Workflow Modules
| Module |
Functions |
What It Controls |
Reference |
| transport |
20 |
Play, stop, record, position, tempo, looping |
api-transport.md |
| mixer |
69 |
Track volume/pan/mute/solo, EQ, routing, effects |
api-mixer.md |
| channels |
48 |
Channel rack, grid bits, step sequencer, notes |
api-channels.md |
Arrangement Modules
| Module |
Functions |
What It Controls |
Reference |
| arrangement + patterns |
9 + 25 |
Markers, time, pattern control, groups |
api-arrangement-patterns.md |
| playlist |
41 |
Playlist tracks, live mode, performance, blocks |
api-playlist.md |
Device & Communication
| Module |
Functions |
What It Controls |
Reference |
| device |
34 |
MIDI I/O, sysex, dispatch, hardware refresh |
api-device.md |
UI & Application Control
| Module |
Functions |
What It Controls |
Reference |
| ui + general |
71 + 24 |
Windows, navigation, undo/redo, version, snap |
api-ui-general.md |
Plugins
| Module |
Functions |
What It Controls |
Reference |
| plugins |
13 |
Plugin parameters, presets, names, colors |
api-plugins.md |
Specialized Hardware Display
| Module |
Functions |
What It Controls |
Reference |
| screen + launchMapPages |
9 + 12 |
AKAI Fire screen, launchpad page management |
api-screen-launchmap.md |
Utilities, Constants & MIDI Reference
| Module |
Functions |
What It Controls |
Reference |
| utils + constants |
21 |
Color conversion, math, note names, MIDI tables |
api-utils-constants.md |
Callbacks & FlMidiMsg
| Module |
Functions |
What It Controls |
Reference |
| callbacks |
26 |
All callback functions, FlMidiMsg class, event flow |
api-callbacks.md |
Non-MIDI Scripting APIs
Piano Roll & Edison
Note, Marker, ScriptDialog, score classes for piano roll manipulation plus Edison enveditor utilities.
See piano-roll-edison.md
FLP File Parsing (PyFLP)
External library for reading/writing .flp project files without FL Studio running. Batch processing, analysis, automated generation.
See pyflp.md
Common Patterns
Minimal MIDI Controller Skeleton
# name=My Controller
# url=https://example.com
import device
import mixer
import transport
def OnInit():
if device.isAssigned():
print(f"Connected: {device.getName()}")
def OnDeInit():
print("Script shut down")
def OnControlChange(msg):
if msg.data1 == 7: # Volume CC
mixer.setTrackVolume(mixer.trackNumber(), msg.data2 / 127.0)
msg.handled = True
def OnNoteOn(msg):
track = msg.data1 % 8
mixer.setActiveTrack(track)
msg.handled = True
def OnRefresh(flags):
pass # Update hardware display here
Key Pattern: Always Check Device Assignment
def OnInit():
if not device.isAssigned():
print("No output device linked!")
return
# Safe to use device.midiOutMsg() etc.
Key Pattern: Mark Events as Handled
def OnControlChange(msg):
if msg.data1 == 7:
mixer.setTrackVolume(0, msg.data2 / 127.0)
msg.handled = True # Prevent FL Studio from also processing this
Key Pattern: Send Feedback to Hardware
def OnRefresh(flags):
if device.isAssigned():
# Update volume fader LED
vol = int(mixer.getTrackVolume(0) * 127)
device.midiOutMsg(0xB0, 0, 7, vol)
For complete examples (MIDI learn, scale enforcer, LED feedback, batch quantization, sysex handling, performance monitoring, automation engine, debugging):
See examples-patterns.md
Best Practices
Performance
- Cache module references at top level (import once)
- Avoid tight loops in MIDI callbacks (keep under 10ms)
- Batch UI updates; use
device.directFeedback() for controller echo
Hardware Integration
- Always check
device.isAssigned() before device functions
- Implement two-way sync for all controls (send feedback on state change)
- Test on real hardware (virtual ports behave differently)
Code Organization
- Separate MIDI mapping from business logic (use a controller class)
- Keep callbacks responsive; offload complex work
- Handle edge cases: invalid indices, missing devices, out-of-range values
Troubleshooting
Script Not Receiving MIDI
- Check
device.isAssigned() returns True
- Verify MIDI input port in FL Studio MIDI Settings
- Ensure callback functions are defined at module level (not nested)
- Check MIDI message status bytes match expected values
Piano Roll Script Not Working
- Verify script is in
Shared\Python\User Scripts folder
- Ensure a pattern is open in piano roll before running
- Access notes via
flpianoroll.score.notes
Performance Issues
- Avoid complex calculations inside
OnIdle() (called every ~20ms)
- Don't repeatedly query values that haven't changed
- Use
device.setHasMeters() only if peak meters are needed
FAQ
- Double-click detection: Use
device.isDoubleClick(index)
- Inter-script communication: Use
device.dispatch(ctrlIndex, message)
- LED control:
device.midiOutMsg(0x90, 0, note, velocity) for note-on LEDs
- processMIDICC vs OnControlChange: Use
On* callbacks for modern code
- GUI access: Limited through
ui module; full UI automation not available
- Multiple devices: Check
device.getName() to identify, handle per-port
Resources
1---
2name: flstudio-scripting
3description: FL Studio Python scripting for MIDI controller development, piano roll manipulation, Edison audio editing, workflow automation, and FLP file parsing with PyFLP. Use for programmatic configuration, device customization, MIDI transport, macros, and save file manipulation. Covers all 427+ API functions across 14 MIDI scripting modules plus piano roll, Edison, and PyFLP contexts.
4metadata:
5 source: https://skillmd.com/skills/modbender/flstudio-scripting
6---
7
8# FL Studio Python Scripting
9
10Complete reference for FL Studio's Python API: MIDI controller scripting (14 modules, 427+ functions), piano roll note manipulation, Edison audio editing, and FLP file parsing with PyFLP.
11
12## Quick Start
13
14### Requirements
15- FL Studio 20.8.4+, Python 3.6+
16
17### Check API Version
18```python
19import general
20print(f"API Version: {general.getVersion()}")
21```
22
23### Script Installation
24Place scripts in `Shared\Python\User Scripts` folder.
25
26---
27
28## Three Scripting Contexts
29
30### 1. MIDI Controller Scripting
31
32**Purpose:** Control FL Studio through hardware MIDI controllers and send feedback to devices.
33**Runs:** Continuously while FL Studio is open.
34**Available modules:** transport, mixer, channels, arrangement, patterns, playlist, device, ui, general, plugins, screen, launchMapPages, utils, callbacks
35
36**Entry points:**
37```python
38def OnInit():
39 """Called when script starts."""
40 pass
41
42def OnDeInit():
43 """Called when script stops."""
44 pass
45
46def OnMidiMsg(msg):
47 """Called for incoming MIDI messages."""
48 pass
49
50def OnControlChange(msg):
51 """Called for CC messages."""
52 pass
53
54def OnNoteOn(msg):
55 """Called for note-on messages."""
56 pass
57
58def OnRefresh(flags):
59 """Called when FL Studio state changes."""
60 pass
61```
62
63### 2. Piano Roll Scripting
64
65**Purpose:** Manipulate notes and markers in the piano roll editor.
66**Runs:** Once when user invokes through Scripts menu.
67**Available modules:** `flpianoroll`, `enveditor`
68
69```python
70import flpianoroll
71score = flpianoroll.score
72for note in score.notes:
73 note.velocity = 0.8 # Set all velocities to 80%
74```
75
76### 3. Edison Audio Scripting
77
78**Purpose:** Edit and process audio samples in Edison.
79**Runs:** Once within Edison's context.
80**Available modules:** `enveditor`
81
82---
83
84## API Module Reference Map
85
86Navigate to the appropriate reference file based on what you need to control.
87Read these files ONLY when you need specific API signatures.
88
89### Core Workflow Modules
90
91| Module | Functions | What It Controls | Reference |
92|--------|-----------|-----------------|-----------|
93| **transport** | 20 | Play, stop, record, position, tempo, looping | [api-transport.md](references/api-transport.md) |
94| **mixer** | 69 | Track volume/pan/mute/solo, EQ, routing, effects | [api-mixer.md](references/api-mixer.md) |
95| **channels** | 48 | Channel rack, grid bits, step sequencer, notes | [api-channels.md](references/api-channels.md) |
96
97### Arrangement Modules
98
99| Module | Functions | What It Controls | Reference |
100|--------|-----------|-----------------|-----------|
101| **arrangement** + **patterns** | 9 + 25 | Markers, time, pattern control, groups | [api-arrangement-patterns.md](references/api-arrangement-patterns.md) |
102| **playlist** | 41 | Playlist tracks, live mode, performance, blocks | [api-playlist.md](references/api-playlist.md) |
103
104### Device & Communication
105
106| Module | Functions | What It Controls | Reference |
107|--------|-----------|-----------------|-----------|
108| **device** | 34 | MIDI I/O, sysex, dispatch, hardware refresh | [api-device.md](references/api-device.md) |
109
110### UI & Application Control
111
112| Module | Functions | What It Controls | Reference |
113|--------|-----------|-----------------|-----------|
114| **ui** + **general** | 71 + 24 | Windows, navigation, undo/redo, version, snap | [api-ui-general.md](references/api-ui-general.md) |
115
116### Plugins
117
118| Module | Functions | What It Controls | Reference |
119|--------|-----------|-----------------|-----------|
120| **plugins** | 13 | Plugin parameters, presets, names, colors | [api-plugins.md](references/api-plugins.md) |
121
122### Specialized Hardware Display
123
124| Module | Functions | What It Controls | Reference |
125|--------|-----------|-----------------|-----------|
126| **screen** + **launchMapPages** | 9 + 12 | AKAI Fire screen, launchpad page management | [api-screen-launchmap.md](references/api-screen-launchmap.md) |
127
128### Utilities, Constants & MIDI Reference
129
130| Module | Functions | What It Controls | Reference |
131|--------|-----------|-----------------|-----------|
132| **utils** + constants | 21 | Color conversion, math, note names, MIDI tables | [api-utils-constants.md](references/api-utils-constants.md) |
133
134### Callbacks & FlMidiMsg
135
136| Module | Functions | What It Controls | Reference |
137|--------|-----------|-----------------|-----------|
138| **callbacks** | 26 | All callback functions, FlMidiMsg class, event flow | [api-callbacks.md](references/api-callbacks.md) |
139
140---
141
142## Non-MIDI Scripting APIs
143
144### Piano Roll & Edison
145Note, Marker, ScriptDialog, score classes for piano roll manipulation plus Edison enveditor utilities.
146See [piano-roll-edison.md](references/piano-roll-edison.md)
147
148### FLP File Parsing (PyFLP)
149External library for reading/writing .flp project files without FL Studio running. Batch processing, analysis, automated generation.
150See [pyflp.md](references/pyflp.md)
151
152---
153
154## Common Patterns
155
156### Minimal MIDI Controller Skeleton
157
158```python
159# name=My Controller
160# url=https://example.com
161
162import device
163import mixer
164import transport
165
166def OnInit():
167 if device.isAssigned():
168 print(f"Connected: {device.getName()}")
169
170def OnDeInit():
171 print("Script shut down")
172
173def OnControlChange(msg):
174 if msg.data1 == 7: # Volume CC
175 mixer.setTrackVolume(mixer.trackNumber(), msg.data2 / 127.0)
176 msg.handled = True
177
178def OnNoteOn(msg):
179 track = msg.data1 % 8
180 mixer.setActiveTrack(track)
181 msg.handled = True
182
183def OnRefresh(flags):
184 pass # Update hardware display here
185```
186
187### Key Pattern: Always Check Device Assignment
188
189```python
190def OnInit():
191 if not device.isAssigned():
192 print("No output device linked!")
193 return
194 # Safe to use device.midiOutMsg() etc.
195```
196
197### Key Pattern: Mark Events as Handled
198
199```python
200def OnControlChange(msg):
201 if msg.data1 == 7:
202 mixer.setTrackVolume(0, msg.data2 / 127.0)
203 msg.handled = True # Prevent FL Studio from also processing this
204```
205
206### Key Pattern: Send Feedback to Hardware
207
208```python
209def OnRefresh(flags):
210 if device.isAssigned():
211 # Update volume fader LED
212 vol = int(mixer.getTrackVolume(0) * 127)
213 device.midiOutMsg(0xB0, 0, 7, vol)
214```
215
216For complete examples (MIDI learn, scale enforcer, LED feedback, batch quantization, sysex handling, performance monitoring, automation engine, debugging):
217See [examples-patterns.md](references/examples-patterns.md)
218
219---
220
221## Best Practices
222
223### Performance
2241. Cache module references at top level (import once)
2252. Avoid tight loops in MIDI callbacks (keep under 10ms)
2263. Batch UI updates; use `device.directFeedback()` for controller echo
227
228### Hardware Integration
2291. Always check `device.isAssigned()` before device functions
2302. Implement two-way sync for all controls (send feedback on state change)
2313. Test on real hardware (virtual ports behave differently)
232
233### Code Organization
2341. Separate MIDI mapping from business logic (use a controller class)
2352. Keep callbacks responsive; offload complex work
2363. Handle edge cases: invalid indices, missing devices, out-of-range values
237
238---
239
240## Troubleshooting
241
242### Script Not Receiving MIDI
2431. Check `device.isAssigned()` returns `True`
2442. Verify MIDI input port in FL Studio MIDI Settings
2453. Ensure callback functions are defined at module level (not nested)
2464. Check MIDI message status bytes match expected values
247
248### Piano Roll Script Not Working
2491. Verify script is in `Shared\Python\User Scripts` folder
2502. Ensure a pattern is open in piano roll before running
2513. Access notes via `flpianoroll.score.notes`
252
253### Performance Issues
2541. Avoid complex calculations inside `OnIdle()` (called every ~20ms)
2552. Don't repeatedly query values that haven't changed
2563. Use `device.setHasMeters()` only if peak meters are needed
257
258---
259
260## FAQ
261
262- **Double-click detection:** Use `device.isDoubleClick(index)`
263- **Inter-script communication:** Use `device.dispatch(ctrlIndex, message)`
264- **LED control:** `device.midiOutMsg(0x90, 0, note, velocity)` for note-on LEDs
265- **processMIDICC vs OnControlChange:** Use `On*` callbacks for modern code
266- **GUI access:** Limited through `ui` module; full UI automation not available
267- **Multiple devices:** Check `device.getName()` to identify, handle per-port
268
269---
270
271## Resources
272
273- **Official FL Studio API:** https://www.image-line.com/fl-studio/modules/python-scripting/
274- **PyFLP GitHub:** https://github.com/demberto/PyFLP
275- **API Functions:** 427+ across 14 modules | **Last Updated:** 2025