Event
#struct EventOne MIDI event, with the tick it happens at.
| Name | Type | Description |
|---|---|---|
tick | int = 0 | When it happens, in ticks from the start. |
status | int = 0 | Which kind of event it is. |
channel | int = 0 | Which of the sixteen channels it is on. |
data1 | int = 0 | The first byte, a note number or a controller. |
data2 | int = 0 | The second byte, a velocity or a value. |
meta | int = 0 | Which meta event it is, when the status says meta. |
value | i64 = 0 | The number a meta event carries, such as a tempo. |
import audio.midi
import compress
func main:
mut f := midi.NewSong(480)
println f.division, f.format, f.tempo as int
println midi.DefaultDivision
mut t := midi.NewTrack()
midi.AddTempo(t, 0, 120.0)
midi.AddProgram(t, 0, 0, 0)
midi.AddControl(t, 0, 7, 100, 0)
mut s := 0
until s < 4:
midi.AddNote(t, s * 480, 240, 60 + s * 2, 100, 0)
s++
end
println t.events.Len()
midi.AddTrack(f, t)
println f.tracks.Len(), midi.TotalTicks(f)
one := t.events.Get(1)
println one.tick, one.status == midi.NoteOn, one.data1, one.data2, one.channel
println midi.NoteOn, midi.NoteOff, midi.ControlChange, midi.ProgramChange, midi.MetaEvent
mut enc := midi.EncodeMIDI(f)
println compress.BufLen(enc) > 22, midi.IsMIDI(enc.data, enc.len)
mut empty := midi.NewSong(480)
println compress.BufLen(midi.EncodeMIDI(empty))
midi.FreeSong(empty)
compress.BufFree(enc)
midi.FreeSong(f)
end480 1 500000 480 11 1 1680 0 false 0 0 0 144 128 176 192 255 true true 0