midiline

package module
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: MIT Imports: 19 Imported by: 1

README

midiline

A manipulation line for MIDI data

Build Status Travis/Linux Documentation

Status

proof of concept

Installation

go get -d github.com/gomidi/midiline/...

Example

package main

import (
	"github.com/gomidi/midiline"
	"github.com/gomidi/midiline/actions/channelchange"
	"github.com/gomidi/midiline/actions/to_cc"
	"github.com/gomidi/midiline/conditions/logic"
	"github.com/gomidi/midiline/conditions/message"
	"github.com/gomidi/midiline/conditions/typ"
	"github.com/gomidi/midiline/value"
	"github.com/gomidi/rtmididrv"
)

func check(err error) {
	if err != nil {
		panic(err.Error())
	}
}

func main() {

	// create a new MIDI line
	line := midiline.New("my line",

		// pass...
		midiline.Pass(
			// ...all note messages on channel 1 within the key range from 12 to 50, ignoring noteoff messages
			logic.And(typ.Channel1, message.NoteKeyRange(12, 50, true)),

			// ...to the action that converts note messages to controller 12 messages
			// by taking the key of the note as value for the controller
			to_cc.Action(12, value.NoteKey()),
		),

		// then change the channel of every channel 1 message to channel 8
		channelchange.Action(1, 8),
	)

	drv, err := rtmididrv.New()
	check(err)
	defer drv.Close()
	ins, err := drv.Ins()
	check(err)
	outs, err := drv.Outs()
	check(err)

	// make a live connection from in port to out port
	ctx := midiline.Connect(ins[0], outs[0])

	// start the connection and pipe the message through the line (the transformed messages will arrive at out)
	stop, err := ctx.Run(line)
	check(err)

	// stop the runner (can only be called once)
	stop <- true
}

Documentation

Index

Constants

View Source
const LineTick = lineTick(false)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {

	// Perform acts on the given message and returns the result.
	// To allow note producing transformers,
	// Perform is called on every tick and
	// when there is no message on the tick, the message is LineTick.
	// This way the action can return messages on every tick
	// (if it wants to). Use case would be a looper or a metronome.
	Perform(Context, midi.Message) midi.Message
}

Action acts on MIDI messages.

func Block

func Block(cond Condition, act Action) Action

Block returns an action that passes the message through the given action if the Condition is not met and returns the original message otherwise.

func Pass

func Pass(cond Condition, act Action) Action

Pass returns an action that passes the message through the given action if the Condition is met and returns the original message otherwise.

type ActionFunc

type ActionFunc func(Context, midi.Message) midi.Message

func (ActionFunc) Perform

func (f ActionFunc) Perform(ctx Context, in midi.Message) midi.Message

type Condition

type Condition interface {
	// IsMet returns whether the condition is met by the given midi.Message
	IsMet(msg midi.Message) bool
}

Condition for a midi.Message

type ConditionFunc

type ConditionFunc func(msg midi.Message) bool

func (ConditionFunc) IsMet

func (m ConditionFunc) IsMet(msg midi.Message) bool

type Context

type Context interface {
	// Resolution returns the ticks of a quarternote
	Resolution() uint32

	// Tick returns the current absolute tick since the beginning
	Tick() uint64

	// Track returns the current track
	// needed for SMF writers
	Track() uint32

	// Bar returns the current bar number
	Bar() uint32

	// Beat returns the current beat in 16ths distances of the start of the current bar
	Beat() uint8

	// TempoBPM returns the current tempo in fractional BPM
	// needed for SMF writers
	TempoBPM() float64

	// TimeSignature returns the current time signature
	// needed for SMF writers
	TimeSig() (num, denom uint8)

	// Schedule schedules the given message deltaticks in the future from now
	Schedule(deltaTicks uint32, msg midi.Message)
}

type DuplicatedLineError

type DuplicatedLineError string

func (DuplicatedLineError) Error

func (e DuplicatedLineError) Error() string

func (DuplicatedLineError) LineName

func (e DuplicatedLineError) LineName() string

type Line

type Line struct {
	// contains filtered or unexported fields
}

Line has a slice of actions that will be called in order when the Run method is called.

func New

func New(name string, acts ...Action) *Line

New returns a new Line for the given Actions.

func (*Line) Check

func (l *Line) Check() error

Check checks, if we got an infinite loop within a Line.

func (*Line) Embed

func (st *Line) Embed() Action

Embed returns a Transformer that proxy its transformation to MIDITransformer that are part of the Stack

func (*Line) Name

func (l *Line) Name() string

func (*Line) String

func (l *Line) String() string

type LineEmbeddingLoopError

type LineEmbeddingLoopError string

func (LineEmbeddingLoopError) Error

func (e LineEmbeddingLoopError) Error() string

func (LineEmbeddingLoopError) LoopPath

func (e LineEmbeddingLoopError) LoopPath() string

type MultiMessage

type MultiMessage []midi.Message

MultiMessage is a helper pseudo midi.Message that wraps multiple midi messages that should be sent at the same time. It can be returned from a callback to be able to make multiple midi messages from single ones.

func (MultiMessage) Raw

func (m MultiMessage) Raw() []byte

Raw will panic if called. It must not be called and only exist to fullfill the midi.Message interface.

func (MultiMessage) String

func (m MultiMessage) String() string

String inspects the MultiMessage for debugging

type PerformOption

type PerformOption func(*performanceCxt)

func LogOutput

func LogOutput() PerformOption

func PerformReaderOptions

func PerformReaderOptions(opts ...mid.ReaderOption) PerformOption

PerformReaderOptions passes the given options (set/unset logging etc.) through to the mid.Reader that receives the midi messages before running through the Stack.

func StdErr

func StdErr(w io.Writer) PerformOption

func StdOut

func StdOut(w io.Writer) PerformOption

type Runner

type Runner interface {
	// Run starts the engines and returns a stop channel
	// that a stop message can be send to and an error if it could not run successfully
	Run(*Line) (stop chan<- bool, err error)
}

func Connect

func Connect(in midi.In, out midi.Out, opts ...PerformOption) Runner

Connect returns a Runner that reads MIDI messages from the in port and writes them to the out port after they have been processed by the stack.

func ConnectSlim

func ConnectSlim(in midi.In, out midi.Out, opts ...mid.ReaderOption) Runner
func Link(inFile, outFile string, opts ...mid.ReaderOption) Runner

Link returns a Runner that reads MIDI messages from the SMF inFile writes them to the SMF outFile, after they have been processed by the stack.

func Play

func Play(inFile string, out midi.Out, opts ...mid.ReaderOption) Runner

Play returns a Runner that reads MIDI messages from the SMF inFile and writes them to the out port by respecting the correct timing (playing style). The messages have been processed by the stack before they reach the out port.

type Valuer

type Valuer interface {
	Condition
	Value(midi.Message) uint8
}

Jump to

Keyboard shortcuts

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