Custom Transform Logic
Advanced topic: Building custom MIDI processing beyond built-in nodes
Overview
Neurode MIDI uses Neuroscript v3 (Rust) as the canonical way to express routing/transforms. Visual authoring compiles to Neuroscript, and scripts are compiled off realtime threads into deterministic programs.
While Neurode MIDI provides built-in routing/transformation primitives, you may need custom logic for:
- Algorithmic composition — Generative patterns, arpeggios, chord progressions
- Adaptive processing — Context-aware transformations based on musical analysis
- Hardware integration — Specialized controller mappings unique to your gear
- Experimental effects — Custom algorithms not covered by standard nodes
Neuroscript (Recommended)
Neuroscript is a musician-focused DSL optimized for common MIDI operations.
When to Use
- Standard transforms (velocity shaping, filtering, remapping)
- Readable, maintainable scripts for musicians
- Fast prototyping without extensive code
Example: Custom Velocity Curve
# Compress loud notes, boost quiet notes
when vel > 100: event(vel = clamp(vel, 90, 110))
when vel < 40: event(vel = clamp(vel + 20, 1, 127))Example: Conditional Layering
# Soft notes go to pad, loud notes to lead
when vel < 60: event(ch = 3)
when vel >= 60: event(ch = 2)Limitations
- No dynamic memory allocation or unbounded loops
- Deterministic per-event execution
- Timing control limited to
send/emitwith durations
Full Reference: Neuroscript Language
Best Practices
1. Start with Built-In Nodes
Before writing custom scripts, check if built-in nodes can achieve the same result:
Prefer built-in transforms (filtering, channel remap, velocity shaping) when they exist.
2. Keep Scripts Small and Focused
Good (focused script):
# Single responsibility: boost quiet notes
when vel < 50: event(vel = clamp(vel + 10, 1, 127))If a script grows beyond ~10–15 lines, consider splitting it into separate routes/presets or refactoring into smaller, commented sections.
3. Test Scripts in Isolation
Use the Playground Simulator to test scripts before embedding in routes:
- Write script
- Test with sample MIDI events
- Verify output
- Apply the script to your route/preset
4. Profile Script Performance
Add Monitor nodes before/after script nodes to measure latency:
[Input] → [Monitor A] → [Script] → [Monitor B] → [Output]If latency exceeds 1ms consistently, consider:
- Simplifying logic
- Using built-in nodes
5. Handle Edge Cases
MIDI events can be unpredictable — always validate:
when type == note: event(note = clamp(note + 12, 0, 127))6. Comment Your Logic
Future you (or other musicians) will thank you:
# Humanize velocity slightly (note events only)
when type == note: event(vel = clamp(vel + 4, 1, 127))