Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

mtxt

> 数据库
Open source

A human-writable text format for musical notes, timing, and expression.

194 stars0 likes1 views
WebsiteGitHub

About

A human-writable text format for musical notes, timing, and expression.

MTXT - Music Text Format

MTXT is a human-editable, text-based format for representing musical performance data. It stores events with precise timing, pitch, and expression values in a simple line-based structure that's easy to edit without requiring specialized tools.

The format is designed for cases where exact performance details matter - arbitrary timings, micro-tuning, dynamic changes, and other expressive parameters. MTXT avoids binary encoding, making it suitable for manual and AI-assisted editing.

Features

  • Beat-based: Events are placed on fractional beats using simple decimal notation (e.g., in a 4/4 time signature, 1 beat = 1 quarter note, so 3.25 represents 3 quarter notes plus 1 sixteenth note).
  • One event per line: Easy to search and modify with any text editor.
  • Human-friendly: Use of musical note names (C4, D#3, etc.) and custom note aliases (e.g. kick or Cmaj7). Hand-crafted files are practical and expressive.
  • Transitions: Built-in support for gliding continuous parameters (CC, tempo) with customizable curves and timing.
  • Real-time ready: Supports streaming musical events and real-time data transfer with transitions and flexible timing.
  • Microtonal support: Built-in cents notation for notes (e.g. C4+50, D4-25) and global tuning commands for alternate tuning systems and just intonation.
  • Flexible organization: Events can be written in any order in the file, with the parser handling chronological sorting.
  • MIDI compatible: Reference implementation includes MIDI to MTXT and MTXT to MIDI conversion.
  • LLM compatible: Can be easily generated and manipulated by language models.
  • Future-proof: Supports up to 65535 channels, arbitrary CC parameters with custom string keys and custom metadata.

Quick Example

…

Rust Library and CLI Tool

This repository includes a reference implementation in Rust that provides:

  • Library (mtxt): Rust crate for parsing and writing MTXT files, with MIDI conversion features.
  • CLI tool: Command-line utility for converting between MIDI and MTXT formats with built-in transforms. Builds can be downloaded from releases.

Basic Usage

bash
mtxt input.mid output.mtxt # MIDI to MTXT
mtxt input.mtxt output.mid # MTXT to MIDI
mtxt input.mtxt output.mtxt --sort # transform MTXT file and sort events by time

Transform Options

The CLI supports various transforms that can be applied during conversion:

Musical Transforms:

  • --transpose - Transpose all notes by semitones (e.g., --transpose +2 or --transpose -12)
  • -q, --quantize - Quantize timing to a grid (e.g., 4 for quarter notes, 16 for 16th notes)
  • --offset - Offset all events by beats (e.g., --offset 1.5, --offset -0.5). Events shifted to negative times are removed.
  • --swing - Apply swing feel (0.0 to 1.0)
  • --humanize - Add timing randomization for humanization (0.0 to 1.0)

Channel Filtering:

  • --include-channels - Include only specific channels (comma-separated, e.g., 1,2,10)
  • --exclude-channels - Exclude specific channels (comma-separated, e.g., 1,2,10)

File Organization:

  • --apply-directives - Apply global directives to events (inline parameters)
  • --extract-directives - Extract common inline parameters into global directives
  • --merge-notes - Merge note on / off pairs into note shorthand events with durations
  • --group-channels - Group events by channel
  • --sort - Sort events by time
  • --indent - Enable timestamp padding

MTXT Specification

Versioning

  • First line must declare version:
    mtxt 1.0

Structure

  • A file consists of:
    1. Version line
    2. Global metadata (optional)
    3. Events (can be in any timestamp order)

Timing

  • All times are in beats specified as fractional numbers. e.g. in a 4/4 time signature, 1 beat = 1 quarter note, so 3.25 represents 3 quarter notes plus 1 sixteenth note.
  • This allows changing the tempo and time signature without affecting the timing of events.
  • Events may appear in any order in the file; the parser will sort them before playback
  • Precision is limited to 5 decimal places (5 microseconds at 120 BPM).

Commands

version (mtxt)

mtxt 
  • Declares the file format version in the major.minor format (e.g., mtxt 1.0).
  • Must be the first non-comment line.

meta

// global meta (applies to the entire file and all channels)
meta global  
// channel meta (applies to a single channel), starting from the specified time
[] meta [ch=]  
  • Adds metadata (e.g., title, author, copyright, trackname, custom types).
  • Value extends from the type to the end of the line (or until inline comment).
  • Channel is optional, if not specified it inherits the channel from the previous ch command.
  • Time is optional, defaults to 0.0.
  • See Standard Meta Types for a list of standard types.
  • Newline characters in need to be escaped to avoid breaking the syntax.

Standard Meta Types

Type Description Example
title Song title meta global title My Song
author Composer/author meta global author John Doe
copyright Copyright notice meta global copyright © 2024 Music Corp
composer Composer name meta global composer John Doe
name Channel name meta ch=1 name Lead Guitar
instrument Instrument name meta ch=2 instrument Steinway Grand
smpte SMPTE offset meta global smpte 00:00:00:00
keysignature Key signature 4.0 meta ch=3 keysignature C major
text General text meta text Verse 1
lyric Lyrics 5.0 meta lyric Hello world
marker Marker/cue point 6.0 meta marker Chorus
cue Cue point 7.0 meta cue Solo begins
program Program name meta global program Piano Ballad
device Device name meta global device OpenPiano 1000
key Key signature meta global key C major
date Creation date meta global date 2024-01-01
genre Musical genre meta global genre Rock
album Album name meta global album Greatest Hits
url Related URL meta global url https://example.com
artist Performer name meta global artist The Band
license Usage license meta global license CC-BY-4.0
generator Software tool meta global generator MySequencer v1.0

ch (channel directive)

ch=
  • Sets the default MIDI channel for subsequent events.
  • Inline ch= on events overrides the default for that event only.
  • Required before channel-dependent events that omit inline ch.

alias (note naming)

alias  
  • Defines a named alias for a note pitch or a chord.
  • ``: Alphanumeric identifier (e.g., snare, Cmaj7).
  • ``: Target note(s), comma-separated if multiple.
  • No timestamp. Applies to all subsequent events in the file until overridden.
  • Name is case-insensitive.
  • Example:
    alias snare C2
    alias Cmaj7 C4,E4,G4,B4  // chord alias
    0.0 note snare
    1.0 note Cmaj7          // plays all 4 notes

vel (default note-on velocity)

vel=
  • Sets the default note-on velocity.
  • Inline vel= on note/on overrides for that event.

offvel (default note-off velocity)

offvel=
  • Sets the default note-off velocity.
  • Inline offvel= on note/off overrides for that event.
  • Defaults to 1.0 if not set.

dur (default note duration)

dur=
  • Sets the default note duration in beats.
  • Inline dur= on note overrides for that event.
  • Defaults to 1.0 if not set.

transition settings

transition_curve=
transition_interval=
  • Sets default transition parameters for cc and tempo.
  • transition_time must be specified per event (default 0.0).
  • See Transitions section for details.
  • Defaults: curve=0.0, interval=1.0.

note (shorthand)

 note  [dur=] [vel=] [offvel=] [ch=]
  • Emits note-on at and note-off at.
  • Uses defaults from dur, vel, offvel, and ch unless overridden.
  • `` is absolute beat BEAT.SUB (0-based). Example: 3.5.
  • `` can be a standard note name or an alias.
  • Standard names support C..B with #/b, octave required (e.g., C4).
    • Allowed: C, C#, Db, D, D#, Eb, E, F, F#, Gb, G, G#, Ab, A, A#, Bb, B
    • Case insensitive: Both uppercase and lowercase are accepted (C4, c4, Bb2, bb2, F#3, f#3)
    • Double accidentals not allowed.
    • Microtonal: +N/-N cents (range -99..+99), applied via pitch bend. Examples: C4+50 (50 cents sharp), D4-25 (25 cents flat), bb2+10.5 (10.5 cents sharp). Positive values require +.

on (note-on)

 on  [vel=] [ch=]
  • Emits a note-on only; useful for streaming.
  • Uses default vel and ch unless overridden.

off (note-off)

 off  [offvel=] [ch=]
  • Emits a note-off only; useful for streaming.
  • Uses default offvel and ch unless overridden.

cc (control change)

 cc [note]   [ch=] [transition_curve=] [transition_time=] [transition_interval=]
  • Sends a control change. `` identifies the parameter.
  • `` is [0.0..1.0]. Uses default ch unless overridden.
  • Uses global transition defaults unless overridden inline.
  • Optional note to apply CC to a specific note. If a note is specified, it applies to that note only.
  • When a note is not specified, it applies to all notes within a channel.
  • Arbitrary string keys can be used for custom parameters (e.g., cc my_param 0.5).

Standard CC Names

Name Range Description
pitch -12.0..12.0 Pitch bend in semitones. 0=none, 1 = one semitone up, -0.005 = half cent down
aftertouch 0.0..1.0 Channel or Polyphonic Aftertouch
vibrato 0.0..1.0 Vibrato depth (Modulation Wheel)
vibrato_rate 0.0..1024.0 Vibrato rate in Hz
breath 0.0..1.0 Breath controller pressure
foot 0.0..1.0 Foot controller pedal position
portamento 0.0..1.0 Portamento glide time
volume 0.0..1.0 Channel volume level
balance -1.0..1.0 Stereo balance (left 0)
pan -1.0..1.0 Stereo panning position (left 0)
expression 0.0..1.0 Expression (secondary volume, relative to main)
sustain 0.0..1.0 Sustain pedal (damper) on/off (> 0.5 is on)
portamento_switch 0.0..1.0 Portamento on/off switch (> 0.5 is on)
sostenuto

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rustformatmidimusicnotation

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库