2024-Present | Tylium
A Modern, Comprehensive MIDI Library for Rust
Summary
cutoff-midi is the foundational MIDI library for the Cutoff ecosystem, a professional-grade platform for advanced audio and MIDI processing. It is a comprehensive, detailed, and forward-looking implementation of the MIDI 1.0 and emerging MIDI 2.0 specifications. By providing a high-level, protocol-agnostic message model, cutoff-midi abstracts away the complexities of the MIDI standards, offering developers a powerful and correct foundation for building sophisticated MIDI applications.
The Challenge: Navigating the Complex Landscape of MIDI Protocols
Developing applications that handle MIDI is challenging. The protocol, while powerful, has decades of history, leading to a complex landscape for developers:
- Protocol Fragmentation: The industry is transitioning from the long-standing MIDI 1.0 to the new, more powerful MIDI 2.0. Applications need to handle both gracefully, preferably through a unified interface.
- Low-Level Complexities: MIDI 1.0 has many low-level details that can be difficult to manage correctly, such as running status, 14-bit Control Change messages (using LSB/MSB), and compound messages like RPN/NRPN.
- Lack of Detailed Device Information: Under MIDI 1.0, it is difficult to programmatically discover the capabilities of a connected device. The new MIDI-CI (Capability Inquiry) and Property Exchange features of MIDI 2.0 solve this, but require a sophisticated implementation.
- Data Transformation: MIDI data often needs to be scaled and transformed. For example, a 7-bit CC value might need to be mapped to a 14-bit parameter, often requiring non-linear curves (e.g., exponential for volume).
The Solution: A Deep, Protocol-Agnostic Implementation
The cutoff-midi crate was designed to solve these challenges by providing a robust, high-level abstraction over the MIDI protocols. It acts as a canonical library that allows developers to work with musical concepts without getting bogged down in the minutiae of byte-level protocol details.
Its design philosophy is centered around a canonical message model. This abstract representation of MIDI messages is independent of the underlying protocol version. This means a developer can create a "Note On" event, and cutoff-midi handles how to correctly format that event for either MIDI 1.0 or MIDI 2.0.
To ensure correctness and compliance with the latest standards, cutoff-midi's implementation of MIDI 2.0 is based directly on the official JSON schemas published by the MIDI Association. This rigorous, specification-driven approach guarantees that its data structures for Property Exchange and device information are accurate.
Key Features
- Canonical Message Model: Simplifies development by abstracting away low-level details like running status and 14-bit CCs, presenting a clean and unified API.
- Extensive Protocol Coverage: The library's implementation is not superficial; it is based on a deep and thorough reading of the official MIDI specifications. It covers dozens of documents for both MIDI 1.0 and MIDI 2.0, including the core specification, numerous extensions (such as General MIDI, MIDI Time Code, and MIDI Polyphonic Expression), and various addenda. This meticulous approach ensures that applications built with
cutoff-midiare robust and compliant with a vast range of MIDI features. - Forward-Looking MIDI 2.0 Support: Implements foundational support for the MIDI 2.0 standard, including data structures for the Universal MIDI Packet (UMP) format, Property Exchange resources, and specifications for MIDI-CI (Capability Inquiry).
- Powerful Value Abstraction: Offers tools for scaling and transforming MIDI parameter values between different resolutions (7-bit, 14-bit, 16-bit, 32-bit) using various curves (linear, exponential, logarithmic), a crucial feature for any serious MIDI application.
- Rich Musical Model: Includes detailed, type-safe models for core musical concepts such as notes, note names, note tracking, and MIDI Time Code (MTC) for synchronization.
- Serialization: Contains modules for serializing and deserializing MIDI data, enabling applications to read and write standard MIDI streams.
Conclusion
cutoff-midi is a foundational component of the Cutoff project. It is more than just a MIDI parser; it is a comprehensive library that provides the necessary features to build advanced MIDI applications. Its detailed implementation of both MIDI 1.0 and 2.0 makes it a solid foundation for any project in the audio software landscape.
Posted by