midiwriter

package
v1.23.7 Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package midiwriter provides a writer for live/streaming/"over the wire" MIDI data.

Usage

import (
	"gitlab.com/gomidi/midi/midiwriter"
	. "gitlab.com/gomidi/midi/midimessage/channel"     // (Channel Messages)
	. "time"

	// you may also want to use these
	// gitlab.com/gomidi/midi/midimessage/realtime   (System Realtime Messages)
	// gitlab.com/gomidi/midi/midimessage/cc         (ControlChange Messages)
	// gitlab.com/gomidi/midi/midimessage/syscommon  (System Common Messages)
	// gitlab.com/gomidi/midi/midimessage/sysex      (system exclusive messages)
)

// given some output
var output io.Writer

wr := midiwriter.New(output)

// simulates pressing down key 65 on MIDI channel 3 with velocity 90
// MIDI channels 1-16 correspond to channel.Channel0 - channel.Channel15.
wr.Write(Channel2.NoteOn(65, 90))

// simulates keep pressing for 1 sec
Sleep(Second)

// simulates releasing key 65 on MIDI channel 3
wr.Write(Channel2.NoteOff(65))
Example
fmt.Println()
var bf bytes.Buffer

wr := midiwriter.New(&bf, midiwriter.NoRunningStatus())
wr.Write(Channel2.Pitchbend(5000))
wr.Write(Channel2.NoteOn(65, 90))
wr.Write(realtime.Reset)
Sleep(Second)
wr.Write(Channel2.NoteOff(65))

rthandler := func(m realtime.Message) {
	fmt.Printf("Realtime: %s\n", m)
}

rd := midireader.New(bytes.NewReader(bf.Bytes()), rthandler)

var m midi.Message
var err error

for {
	m, err = rd.Read()

	// breaking at least with io.EOF
	if err != nil {
		break
	}

	// inspect
	fmt.Println(m)

	switch v := m.(type) {
	case NoteOn:
		fmt.Printf("NoteOn at channel %v: key %v velocity %v\n", v.Channel(), v.Key(), v.Velocity())
	case NoteOff:
		fmt.Printf("NoteOff at channel %v: key %v\n", v.Channel(), v.Key())
	}

}
Output:

channel.Pitchbend channel 2 value 5000 absValue 13192
channel.NoteOn channel 2 key 65 velocity 90
NoteOn at channel 2: key 65 velocity 90
Realtime: Reset
channel.NoteOff channel 2 key 65
NoteOff at channel 2: key 65

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(dest io.Writer, opts ...Option) (wr midi.Writer)

New returns a new midi.Writer.

The Writer does no buffering and makes no attempt to close dest.

By default the writer uses running status for efficiency. You can disable that behaviour by passing the NoRunningStatus() option. If you don't know what running status is, keep the default.

Types

type Option

type Option func(*config)

Option is a configuration option for a writer

func NoRunningStatus

func NoRunningStatus() Option

NoRunningStatus is an option for the writer that prevents it from using the running status.

Jump to

Keyboard shortcuts

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