foot pedal and midi fun, some dmd speed enhancements. Forum argues about @safe by default on extern.

Posted 2020-05-25

While the forum went on about DIP 1028, I had some fun with other gadgets and dmd enhancements.

Core D Development Statistics

In the community

Community announcements

See more at the announce forum.

@safe stuff

I wrote about my ideal solution to the @safe debate months ago, but another idea came to mind this week too: what if we did more inference? Consider this: all functions get inferred, like templates do now. (Preferably with improved error messages! but meh) The explicit annotations serve to do two things: 1) opt-in to errors if the guarantees are violated (again, same as marking a template or unittest @safe now) and 2) provides an API compatibility guarantee for the future.

The #2 thing there is what's interesting: inference doesn't work when there's no body and is liable to change at any time, so it isn't ideal for everything. But when you do get explicit, you're making a long-term promise to support that, which becomes suitable for extern linking too.

I think there's a lot of potential there where everyone can win.

What Adam is working on

I didn't write in the blog last week since I used my free time playing with two other things: a midi keyboard and a little homemade foot pedal controller.

Foot controller

I want to add more input options to my computer and my feet are semi-free, so I played with the idea of making a foot pedal device. I started with the control off my sewing machine, which electronically is just a variable resistor. It has a 1/8 inch headphone-style plug to connect it to the machine, so I took an old laptop apart and removed its headphone jack. I then wired that up to my arduino on one of its analog in ports along with a couple resistors to complete the circuit and boom, it sends numbers back to my Linux box on the usb serial device. Slight latency - I believe that's the usb buffer, will look into it later, but it works!

Of course, it is a slight hassle to take the pedal back and forth from the computer and the sewing machine when I use that, but it is still cool to make it out of stuff I already had. Now, just need to rig my programs to actually use the new input...

BTW I still wanna put D on the arduino, but actually, I kinda like their little sketch thingy. The ide, built-in libs, and programming language are all good enough as-is for the little things I actually do with this thing. So I'm sure someday I'll make it happen, but probably not very soon.

MIDI

I also played a bit more with midi input. I got a $35 little midi mini keyboard and while it isn't as nice to play as my full-size keyboard, it is miniature and it was cheap so it works out well on balance - much easier to play with on my desk among other things.

Anyway, I made a little program to read the input, display it on screen (in a keyboard and on a music staff), and play it through a midi device while recording it to a file. The program can also play back existing midi files, showing the same display.

I plan to use this as a practice helper and teaching aid to improve playing with the family. I have also just wanted to write a midi sequencer for my jrpg game for basically ever - and I started my midi code back in 2008 - but now it is actually coming together! My libs are actually usable for a variety of things now and that is cool. I figure I'll also run it on the raspberry pi to turn stuff on and off with the music on the gpio pins too - will be tons of fun. Maybe even trigger script events in the game for rhythmic cutscenes.

Much more to come later.

dmd

My PR to discard unnecessary parts of templates was merged and Walter is enthusiastic about taking the next step too. With the two things he did and mine combined, on dmd master, my reflection-based web app builds in 2.5s instead of the 3.0 it was before, and peak memory consumption is down about 10% too. We're gonna keep working on this.

Just for laughs

Last time, I wrote about a raspberry pi based intercom. This week, I want to laugh a bit at myself. It always seems kinda ridiculous to me to overengineer a fundamentally simple task.

This raspberry pi intercom uses a full-featured computer to read audio and send it over UDP to the next room. It is simple enough code, but what other options were there?

Well, I could just send an analog signal down a wire, or use a tiny fm radio transmitter... or, of course, the simplest solution... just yell up the stairs!

But, sometimes, of course, the simplest thing isn't necessarily the "lowest tech". Might use wifi instead of an analog broadcast just because the equipment is already there or whatever. Still... it makes me laugh a little.