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 ¶
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.
Click to show internal directories.
Click to hide internal directories.