midi

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package midi writes a score (tracks of notes, placed by bar and beat) as a standard MIDI file that any DAW opens. A score is cleaned first: what can't be played is dropped and the rest kept inside the piece.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmpty = errors.New("midi: the score has no notes that can be played")

Functions

func Drums

func Drums() []string

Drums are the names a note on drums can have.

func Instruments

func Instruments() []string

Instruments are what a track can be played on.

func Render

func Render(title string, score []byte) ([]byte, error)

Render writes a score, given as JSON and cleaned, as a type 1 MIDI file named title.

Types

type Format

type Format struct{}

func (Format) CleanData

func (Format) CleanData(raw json.RawMessage) (json.RawMessage, error)

func (Format) DataHelp

func (Format) DataHelp() string

func (Format) DataSchema

func (Format) DataSchema() map[string]any

func (Format) Describe

func (Format) Describe() string

func (Format) Ext

func (Format) Ext() string

func (Format) MediaType

func (Format) MediaType() string

func (Format) Name

func (Format) Name() string

func (Format) Needs

func (Format) Needs() string

func (Format) Render

func (Format) Render(w memory.Work, _ string) ([]byte, error)

func (Format) WriteHelp

func (Format) WriteHelp() string

type Note

type Note struct {
	Pitch    string  `json:"pitch"`    // "C4" (middle C), "F#3", "Bb2"; a drum's name on drums, e.g. "kick"
	Bar      int     `json:"bar"`      // from 1
	Beat     float64 `json:"beat"`     // from 1; 2.5 is the "and" of 2
	Length   float64 `json:"length"`   // in beats
	Velocity int     `json:"velocity"` // 1 to 127
}

type Score

type Score struct {
	BPM         float64 `json:"bpm"`
	BeatsPerBar int     `json:"beats_per_bar"`
	Bars        int     `json:"bars"`
	Tracks      []Track `json:"tracks"`
}

func Parse

func Parse(data []byte) (Score, error)

func (Score) Clean

func (s Score) Clean() (Score, error)

Clean keeps what can be played: a tempo from 40 to 240 (else 90), 2 to 12 beats a bar (else 4), known instruments and pitches, and notes inside the piece, cut at its end. Bars, if not given, is where the last note ends.

type Track

type Track struct {
	Name       string `json:"name"`
	Instrument string `json:"instrument"` // one of Instruments
	Notes      []Note `json:"notes"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL