May 2018
Intermediate to advanced
412 pages
9h 3m
English
Elixir comes with the following protocols:
To play with these, let’s work with MIDI files.
A MIDI file consists of a sequence of variable-length frames. Each frame contains a four-character type, a 32-bit length, and then length bytes of data.[38]
We’ll define a module that represents the MIDI file content as a struct, because the struct lets us use it with protocols. The file also defines a submodule for the individual frame structure.
| | defmodule Midi do |
| | |
| | defstruct(content: <<>>) |
| | |
| | defmodule Frame do |
| | defstruct( |
| | type: "xxxx", |
| | length: 0, |
| | data: <<>> |
| | ) |
| | |
| | def to_binary(%Midi.Frame{type: type, length: length, data: ... |
Read now
Unlock full access