song taken care of at the click of a foot-switch is quite a luxury!
Externally, the Box interfaces not only to
a keyboard but also to the MIDI Replay app
Figure 7 shows a musical score
generated by a free sequencer called Anvil
Studio, from a track recorded on the Box.
Figure 8 shows an example of how ranges can be used
for splits and layers.
Design Challenges of a
Real Time MIDI System
So, how do we turn this logical and musical overview
into a reliable high-performance system? The stakes are
high because system failure mid-performance could be
This is a real time system with a demanding spec: The
notes a musician plays must be processed seamlessly and
without delay, applying range and transpose logic, echoed
out on selected channels, and possibly recorded. At the
same time, any previously recorded tracks might also play
back. We know that ‘without delay’ is not possible. The
key words that come to mind are latency, accuracy, and
precision. For a good musical experience, latency must
ideally be 10 milliseconds or less, timing accuracy similar,
notes must never ‘stick,’ and the user interface must be
snappy and reliable.
It helps to think about a likely worst-case scenario
rather than an absolute worst-case. For example, a likely
worst-case recording scenario is not tripping onto the
keyboard and playing every note simultaneously! Rather it’s
probably recording 10 to 20 notes per second for ‘busy’
music, down to almost nothing for very sparse music.
Taking this pragmatic approach, if we occasionally
drive the system beyond this likely worst-case and
introduce additional hardly noticeable delay, then so be it!
Suddenly, this project begins to look within the reach
of a modest mid-range microcontroller.
Task Scheduling Strategies
In real time computing systems where a lot of tasks
need to be performed, task scheduling is important. This
is a complex subject with many variants. The simplest is
what’s called round-robin where there’s a loop and each
task in the loop is run one after the other; the loop then
repeats over and over. At the other extreme is a real time
operating system with complex features and operation
aiming for the minimal possible delay in execution.
The middle ground contains a round-robin with
interrupts. Interrupt routines deal with the very urgent
needs of the hardware and then set flags. The main loop
polls the flags and does any follow-up processing required
by the interrupts.
An example might be incoming UART data that if left
too long could be overwritten by the next incoming data
byte. The time-critical task of retrieving the data is handled
as soon as the interrupt fires by moving the data byte into
a circular buffer. However, processing the data byte is
usually what’s called a ‘soft’ real time requirement and can
be handled later by the main loop when it gets around to it.
Although it’s useful to think of a robin hopping round
each task, Wiki tells us that the term actually dates from
the 17th century French ‘ruban rond’ (round ribbon),
describing the practice of signatories to petitions against
authority (usually government officials petitioning the
Crown), appending their names on a document in a nonhierarchical circle or ribbon pattern.
; FIGURE 9. The physical diagram.
; FIGURE 8. At the touch of a button:
Keyboard splits and ranges.
September/October 2018 29