Technical Details of the AKAI MPKmini Professional MIDI Keyboard

This year I impulse-bought an AKAI MPK mini Pro 2-octave MIDI device.

AIKI MPKmini Pro

And found that, apparently, if you want to do anything with Midi music, you buy a Mac.

Well, I’ve always found Mac/Apple UI to be unusable, so that’s out.

Anyway, it turned out to be easy to get MIDI messages from a USB device to a Python program using python-mido. And, after some dithering, creating sound from Midi was do-able. I tweaked one of several variants of fluidsynth.py on GitHub. The actual instruments came from various SoundFont files downloaded from the magical Internet. My favorite of the 48 I have is gigabyte-sized Compifont_13082016.sf2.

Re-inventing the wheel can be entertaining.

In the course of playing with the AKAI I made the following notes about the AKAI’s sysex and light control logic. Make of them what you will.

"""

Some things found about the Akai Pro Mini using (after plugging the device alone in to USB bus 3 - the near plug on the front panel of spring):
    sudo modprobe usbmon                        # makes the /dev/usb/usbmon[0-7] devices
    sudo cat /sys/kernel/debug/usb/usbmon/3u    # doesn't print more than 24 real data bytes at a time (32 bytes packaged in 8 4-byte words)

    Note: Each 4 bytes has a 04 as the 1st byte and a 07 instead of 04 on the last 3 real data bytes.

Or:
    sudo tcpdump -i usbmon3 -x

Note:       https://github.com/mungewell/mpd-utils/blob/master/sysex/sysex_mk2.md   has some sysex reverse-eng info for the device
Note:       private/akai/APC40Mk2_Communications_Protocol_v1.2.pdf                  for a similar device (some note on the web said this MPKmini doesn't have such a doc)

MPK Mini sysex from device

sysex data=(
71,         Akai device     71==0x47
0,          More Akai dev?                      (which particular device? - 0x7f is broadcast, apparently, and 0x7e is non-real-time?)
38,         Akai model      38==0x26
103,        sysex function  103|0x67 is (prog_memory below: 0..4=RAM|prog1..4) coming from device.
                            102|0x66 requests a program (prog_memory below: 0..4=RAM|prog1..4) from device.
                            100|0x64 puts program to device.
                             96|0x60 requests the knob positions (see the code for example).
                             97|0x61 is knob positions from the device.
0,          hi-7-bits of how many bytes
109,        how many more bytes there are or are meant to be if the device didn't have bugs?

0,          prog memory     0=RAM 1=prog1 2..4=prog2..4

0,          pad channel     0..15

0,          key channel     0..15
4,          key octave      0..8    4 + octave      (changes LEDs)

0,          arp             off=0 on=1              (changes LED)
0,          arp mode        0..5
0,          arp time div    0..7
0,          arp clock       internal=0 external=1
0,          arp latch       on=1    off=0
0,          arp swing       0..5    50%|55%|57%|59%|61%|64%
3,          arp tempo taps  2..4
1,          hi bit          arp tempo  30..240
0,          lo 7 bits       arp tempo  30..240
0,          arp octave 0..3 (displayed on-screen in Akai setup program and on device's keys in red as 1..4)

0,          0=pitchbend     1=cc1 2=cc2
0,          cc1|cc2-down    0..127
0,              cc2-up      0..127
2,          cc2
65,         cc2-down 65
64,         cc2-up   64

48,         note_on note when not in CC or PC mode
0,          cc
0,          pc
1,          momentary=0 toggle=1
49,1,1,1,
50,2,2,1,
51,3,3,1,
52,4,4,1,
53,5,5,1,
54,6,6,1,
55,7,7,1,
56,8,8,1,
57,9,9,1,
58,10,10,1,
59,11,11,1,
60,12,12,1,
61,13,13,1,
62,14,14,1,
63,15,15,1,

0,      cc
0,      lo
127,    hi
1,0,127,
2,0,127,
3,0,127,
4,0,127,
5,0,127,
6,0,127,
7,0,127,

12          0..24   12 + transpose of -12..12
)


"""

#
#
#   If the device is in the right state, apparently any channel 0 note_on (non-127?) will turn off the PROG_CHANGE light until some other note_on messages are sent or something.
#   led_lite values:
#       0..2    At start-up most recent is Prog Change - it turns off/on.
#       3       Apr On/Off
#       4       Tap_tempo changes only if human has turned off Arp
#       5       Octave down
#       6       Octave up
#       7       Full level
#       8       ?
#       9..16   Pads
#       17..24  Most recently used lite.
#       25      Bank A/B if Green, off goes to off or red, whichever it was last set by the human. Human-set red cannot be turned off.
#       26      CC
#       27      Prog Change
#       Other led_lite values are just weird. Most recent lite changed or something is affected.
#   The lites don't affect the meaning of the button. The button must be hand-toggled from its logical state to get to a state that matches the lite after the lite is turned off.
#
#   The 127-ness came from a comment at: https://cycling74.com/forums/akai-mpk-mini-send-get-signals-to-light-buttons
#
#
AKAI_MPK_MINI_LITES   = [
    [ 3,    "Arp",          ],
    [ 4,    "Tap_Tempo",    ],
    [ 5,    "Oct_down",     ],
    [ 6,    "Oct_up",       ],
    [ 7,    "Full_level",   ],
    [ 9,    "Pad_1",        ],
    [ 10,   "Pad_2",        ],
    [ 11,   "Pad_3"         ],
    [ 12,   "Pad_4",        ],
    [ 13,   "Pad_5",        ],
    [ 14,   "Pad_6",        ],
    [ 15,   "Pad_7",        ],
    [ 16,   "Pad_8",        ],
    [ 25,   "Bank_A/B",     ],
    [ 26,   "CC",           ],
    [ 27,   "Prog_change",  ],
                        ]


A Better Way of Scoring

Racquetball’s official scoring method is a millstone around the game’s neck.

What’s better?

Let’s score to make games more even, with longer rallies.

How?

First: Rally scoring. A point is scored on every rally, not just when the server wins a rally. Volleyball went to rally scoring a couple decades ago. Big improvement.

Second: Who serves? The person with the lower score chooses. If the score is even, the person who did not have the serve-choice the previous serve chooses the server.

Third: Single serve. A fault is a point for the opponent. (I prefer two serves in racquetball, but that’s probably not the best way to do it. Most probably not the best in other sports.)

Fourth: The serve rotates in team games, doubles, etc., when the serve-choice changes. And the serve-choice side can force a single rotation of the serving side at any other time.

Fifth: Game is to 15 – win by two.

The result: Short, competitive games between players of differing skills. Longer rallies because the weaker player starts more rallies with an edge.

Bonus: Faster games. More action in a match. More fun to play. More fun to watch.

Applies to other games: Volleyball, ping-pong, badminton, squash. You name it.

Racquetball is inherently fast and action-packed. Why should it have a plodding scoring system? Why not a system that fits the game?

Which leads to how games will change when judging and ref’ing become automated. Why should points only be counted once a rally? But that’s another subject for another day.

Make Facebook pleasant again

I go to Facebook every few days, weeks or whatever. Kids’ pics. Volleyball happenings. Doings of people I’ve known over the years.

What’s happened to my follow-feed, though, is people I know to be fine people in real life appear in the feed as the girl on the left:

Tantrum Time

This is disheartening at best.

Politics is entertaining, but, golly, let’s not scream at our favorite character on TV when they do something dumb. Get a grip.

But, of course, the other guy will never get a grip.

So, for Firefox, there’s Grease Monkey and my quick and dirty Grease Monkey script, FaceBookFix.user.js, to the rescue.

This script simply takes Facebook posts off screen if they contain, in text form (sadly not in images), any of a list of words.

It’s not heavily tested, to say the least. Which is to say, I tried it a couple times.

I made it easy to add or delete banned words. Non-programmers can change the script if they can find it on their disk and save it as a text file from WordPad or a better text editor.

The results are nice. My feed is now pleasant. Again. “Never do yourself what a computer can do for you,” so the computer now lets me see the real news un-flooded by noise. (If this post makes it to Facebook, I can’t write “f*** news” or the script will make the post invisible to me!)

Oh. Here’s the whole script as of this moment:

// ==UserScript==
// @name        FaceBookFix
// @namespace   https://www.tranzoa.net/~alex
// @description Get rid of sad Facebook tantrums.    https://www.tranzoa.net/alex/public_stuff/FaceBookFix.user.js
// @include     https://www.facebook.com/
// @version     1
// @grant       none
// ==/UserScript==

/***

    FaceBook posts containing any of these listed strings are whacked.

    The strings are in in no particular order.

    Change as you see fit.

    Non-programmers, leave the last one as the last one.

    Non-programers, for syntax reasons, do not put any:
        single-quote         ( ' )
        pipe/vertical_stroke ( | )
        backslash            ( \ )
    characters in any of the strings.

***/
var find_these_strings  = [
    'killary',
    'drumpf',
    'obozo',
    'shillary',
    'repuglican',
    'democrap',
    'libtard',
    'faux news',
    'hilliary',         // I forget other Internet commenters' alternate spellings. More to come, for sure.
    'trump',
    'hillary',
    'clinton',
    'HRC',
    'DJT',
    'obama',
    'biden',
    'pence',
    'nixon',
    'watergate',
    'reagan',
    'steve bannon',
    'stevebannon',
    'bernie sanders',
    'berniesanders',
    'bernie',           // Sorry about this, Bernie-from-Dimas-days. Your brand has been trashed.
    'sanders',
    'george bush',      // 'bush' is just too generic
    'georgebush',
    ' g bush',
    ' gbush',
    ' gw bush',
    ' gwbush',
    ' h bush',
    ' hbush',
    ' hw bush',         // did I get these bushes right?
    ' hwbush',
    'kkk',              // why are Hollywood and the news guys obsessed with the KKK? No one in the real world cares about them.
    'mcconnell',        // maybe this should be only mitch McConnell
    'sean spicer',
    'seanspicer',
    'harry reid',
    'harryreid',
    'paul ryan',
    'paulryan',
    'muslim',
    'impeach',
    'senate',
    'house of rep',
    'parliment',
    'merkel',
    'abortion',
    'pro-life',
    'prolife',
    'pro-choice',
    'prochoice',
    'occupy democrats',
    'occupy wall',
    'fake news',
    'iran',
    'iraq',
    'isreal',
    'saudia arabia',
    'potus',
    'scotus',
    'executive order',
    'daily show',       // ? poeple seem to feel this show is really important when it discusses politics
    'fuck',             // the whole profanity list should be here.
    'shit',
    'Note: Leave this here at the end of the list.'
    ];
find_these_strings  = find_these_strings.join('|').toLowerCase().split('|');
find_these_strings.pop();       // get rid of the comment at the end


(function (){

function    fix_this_facebook_thing()
{
    var divs = document.getElementsByTagName("div");                            //  Find all DIV elements in the page
    // window.console.log("fixing " + Date.now() + " " + divs.length);
    for (var el_number in divs)                                                 //  Python is *so* superior to JavaScript
    {
        var el  = divs[el_number];
        if ((el.id != undefined) && el.id.startsWith('hyperfeed_story_id_'))    //  For each post in the feed
        {
            var htm = el.innerHTML.toLowerCase();                               //  Look for any of the strings without regard to case
            // window.console.log("scanning " + el.id + " " + htm.length);
            for (string_number in find_these_strings)
            {
                var fs  = find_these_strings[string_number];                    //      For each of the strings to find
                if  (htm.indexOf(fs) >= 0)                                      //          Is the string in the post in text form? (sadly missing them in images and videos)
                {
                    el.style.display    = 'none';                               //          Yes. Take the post off screen
                    // window.console.log("whacked: " + fs + " in " + el.id);
                    break;                                                      //          And don't keep looking in the this post for more matches.
                }
            }
        }
    }
}


var timeout_every_couple_seconds = window.setInterval(fix_this_facebook_thing, 2017);


}());


// eof

Sending ad requests to the bit bucket

To send ad requests from your browser to the bit bucket, a common trick is to use the hosts file to send ad farm HTTP requests to a non-existent server.

A non-existent server can make the browser wait too long for gobs of HTTP requests.

So, give a machine running Apache an interface for an IP address that isn’t used on your local network. 192.168.99.99, for instance. Or 10.252.252.252.

Then add this sort of thing to your /etc/apache2/sites-enabled/200-vhosts file:

<VirtualHost 10.252.252.252>
  ServerName    helload
  DocumentRoot  /var/www/spam_ad_dir/
  ErrorLog      /var/log/apache2/spam_ad_error.log
  CustomLog     /var/log/apache2/spam_ad_access.log combined
  RedirectMatch 403 /* 
</VirtualHost>

Change the IP address as appropriate. And, you can make an empty directory at /var/www/spam_ad_dir/

For amusement, read the spam_ad_access.log.