Midi Time Signature Explained

FF 58 04 nn dd cc bb – is the construct of the time signature. So this event lives on the track. Outside on the midi file is the 5th element called ticks_per_beat. This is so the notation of the signature used by musicians is decoupled from tempo. We can still preserve the same structure when we play the file faster or slower so let’s plug in some parameters. Below is example of a file I’m working on, sorry if different from yours. I’ve set the tempo to 110 (different from default) so it ends up in the file.

[Midi File Level]
ticks_per_beat = 120

[Track Level - MIDO]
clocks_per_click = 36
denominator = 4
numerator = 4
notated_32nd_notes_per_beat = 8

I have created a midi file in Ableton with half-notes just so we stay sane and can reverse engineer the math for mido package specific. Just so we’re clear I also assumed 4/4 time signature. You don’t have to worry about hex values everything here above is already decimal (!!)

[Midi File Level]
Ticks Per Beat = Time per beat - Microseconds Per MIDI quarter-note [FF 51 03]
RAW HEX = FF 51 03 05 16 15 - number encoded in last 3 bytes
HEX-0852AF = DEC-545455
1 minute = 60,000,000 microseconds
60,000,000 / 545455 = 109.999908333409722 (float) or 110.00 (with 2 digit accuracy)

[Track Level]
RAW HEX = FF 58 04 04 02 24 08
4th byte - nn - numerator  = 04hex = 2dec -  same
5th byte - dd = denominator = 02hex = 2dec - 2^2 = 4 same
6th byte - cc = clocks_per_click = 24hex and 36dec same
7th byte - bb = notated_32nd_notes_per_beat = 8 same

So just to recap. Midi-level ticks_per_beat are providing very accurate actual time representation. How fast do we want to play your midi structure. Track-level bytes 4-7 of the FF 58 04 message give us musical structure. Decoupled (actual time microseconds, bpms etc) from music structure (bars, quarternotes etc)

Wikipedia has audible example of 4/4 vs 12/8
https://en.wikipedia.org/wiki/Time_signature#Compound

And probably my favourite example
Return to Sauce by Infected Mushroom
https://www.youtube.com/watch?v=fg1WoZOykUI

Fav Mac Terminal Setup

Andale Mono 13

export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=GxFxCxDxCxegedabagaced

Python class attributes from/to dictionary

class McItems(dict):

    attrs = ["guid"]

    def as_dict(self):
        return self.__dict__

    def from_dict(self, *val, **kwargs):
        for key in val:
            setattr(self, key, val[key])
        for key in kwargs:
            setattr(self, key, kwargs[key])

    def from_dict_selected(self, *val, **kwargs):
        if len(self.attrs) == 1:
            raise "overwrite for McItems has to have attrs with list of more than one item"

        for key in val:
            if key in val.attrs:
                setattr(self, key, val[key])

Spotify in Container

REF: https://stackoverflow.com/questions/41083436/how-to-play-sound-in-a-docker-container

you will notice

docker run -it \
    -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket
    -e DISPLAY=unix$DISPLAY \ # pass the display
    --device /dev/snd \ # sound
    --name spotify \
    jess/spotify
or for Chrome, at the end

docker run -it \
    --net host \ # may as well YOLO
    --cpuset-cpus 0 \ # control the cpu
    --memory 512mb \ # max memory it can use
    -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket
    -e DISPLAY=unix$DISPLAY \ # pass the display
    -v $HOME/Downloads:/root/Downloads \ # optional, but nice
    -v $HOME/.config/google-chrome/:/data \ # if you want to save state
    --device /dev/snd \ # so we have sound
    --name chrome \
    jess/chrome