Crate mseq

Crate mseq 

Source
Expand description

§mseq

mseq is a lightweight MIDI sequencer framework written in Rust.
It provides a flexible core for building sequencers that can run in standalone, master, or slave mode, with synchronization over standard MIDI clock and transport messages.

§Overview

The sequencer is driven by a user-provided Conductor implementation, which defines how the sequencer initializes, progresses at each clock tick, and reacts to external MIDI messages. The core engine manages timing, MIDI input/output, and synchronization.

  • No input → runs standalone with its internal clock and transport, generating MIDI clock and transport messages but ignoring external MIDI input.
  • Master mode → runs with its internal clock while also processing incoming MIDI events (except for external clock/transport).
  • Slave mode → synchronizes playback to an external MIDI clock and responds to Start/Stop/Continue messages, dynamically adjusting BPM to match the clock source.

§Usage

The entry point of the crate is the run function:

use mseq::{run, Conductor, Context, Instruction, MidiInParam, MidiMessage};

struct MyConductor;

impl Conductor for MyConductor {
    fn init(&mut self, _ctx: &mut Context) -> Vec<Instruction> {
        // Return setup instructions (e.g., reset all controllers)
        vec![]
    }

    fn update(&mut self, _ctx: &mut Context) -> Vec<Instruction> {
        // Called each clock tick: return note events or other MIDI instructions
        vec![]
    }

    fn handle_input(&mut self, input: MidiMessage, _ctx: &Context) -> Vec<Instruction> {
        vec![]
    }
}

fn main() -> Result<(), mseq::MSeqError> {
    let conductor = MyConductor;
    let out_port = None; // Ask user for output port
    let midi_in = None;  // Run standalone (no input, master clock/transport)
    run(conductor, out_port, midi_in)
}

§Features

  • Real-time MIDI clock generation and synchronization
  • Master/slave transport control with Start/Stop/Continue handling
  • Flexible Conductor trait for defining sequencer logic
  • Easy-to-implement tracks via the Track trait
  • Thread-safe, minimal core designed for real-time responsiveness

Modules§

acid
The acid module provides tools for generating and loading acid-style tracks into MSeq.
arp
The arp module provides tools for generating and loading arp-style tracks into MSeq.
div
The div module provides tools for generating and loading clock divider-style tracks into MSeq.
index
The index module provides functionality for loading multiple track types into the MSeq sequencer from a unified .toml index file.
midi
The midi module provides tools for generating and loading MIDI tracks into MSeq.

Structs§

Context
An object of type Context is passed to the user’s Conductor at each clock tick via the Conductor::update method. It provides a high-level interface to send system MIDI messages and modify system parameters.
DeteTrack
A deterministic track implementation.
MidiController
Provides a reusable MIDI interface and core logic across different platforms.
MidiInParam
MIDI input connection parameters.
MidiNote
Note that can be sent through a MIDI message.

Enums§

Ignore
An enum that is used to specify what kind of MIDI messages should be ignored when receiving messages.
Instruction
Represents instructions that can be interpreted and processed by the MidiController.
MSeqError
Error type of mseq
MidiMessage
Represents a parsed MIDI instruction.
Note
Represents 1 note of the chromatic scale.
TrackError
An error type representing issues that may occur when loading or generating tracks.

Traits§

Conductor
Entry point for user-defined sequencer behavior.
MidiOut
This trait is not intended to be implemented by user code.
Track
Abstraction for a sequencer track.

Functions§

param_value
Performs a linear conversion from [0.0, 1.0] to [0, 127]. If v is smaller than 0.0 return 0. If v is greater than 1.0 return 127. The main purpose of this function is to be used with MIDI control changes (CC).
run
mseq entry point.

Type Aliases§

InputQueue
Inputs queue to process.