Sunday, April 12, 2020

Abjad and Lilypond: Tools for Algorithmic Composition: First Look

Lilypond, which for some reason I keep calling Lilypad by mistake, is a TeX like tool for engraving beautiful sheet music.  Unlike Finale or Sibelius it does not use WYSIWYG mouse and keyboard input.  Rather you enter source code in a text editor, and use Lilypond to render it.

The advantages of that more than make up for the lack of point and click instant gratification.  What advantages?  Well there is the quality of the output, which is at least on par with those other programs, and maybe better.  More importantly for someone who wishes to do Algorithmic Composition is the simple fact that it expects a text file in a specific format as input.

Sounds like something that a computer program should be able to generate amirite?  Indeed, that is the purpose of Abjad.  Abjad is an extensive library of routines and objects that allow Python code to generate music that is in the Lilypond format, and thus can be beautifully rendered as sheet music for a performer.

I've been working on Electronic Music for some years, but only recently have I been given the opportunity to work with a live musician playing an Orchestra instrument.  It is one thing to program a sequencer to generate MIDI that is fed directly into another instrument, quite another to be able to hand some music to a musician with the expectation that they will be able to read and perform it.

Whenever I say "yes" to a project like that, it is always a bit like jumping off a cliff, and hoping that I will find water in which I can swim beneath.  Abjad and Lilypond are indeed sufficient water, and I have started swimming.  I don't want to go into much depth about them, partly because I still don't know much, but also because if you follow the links to the projects you will find a wealth of examples.  I found the Ligeti score example particularly helpful for my purposes.

One thing I do want to mention is some confusion with the word "Note".  That may seem silly, but bear with me.  A note might refer to a note in the scale: ABCDEFG, to a note on the piano keyboard: say A below Middle C, or to a  Midi note: Say note 66.  In Midi for example you can send a NoteOn and a NoteOff, but the notion of a quarter note is non-existent (though in Midifiles of course there are temporal delays, so duration can be represented).

In Lilypond and Abjad a Note is a combination of a piano or Midi type note, and a duration. It is possible to specify notes either by name, say c' or by number.  For algorithmic composition the number representation is much simpler.  Somewhat annoyingly (to me) the number assigned to Middle C is zero, so even if you are doing a simple piece of piano music you will have to deal with negative integers.  Yes I know that they were already well used by the 1500s, but if Leibniz thought they were "invalid", and Pascal "regarded the subtraction of 4 from 0 as utter nonsense" then maybe I am in good company.

In any event getting started is simple enough, the example at the Abjad front page includes these simple lines:
duration = abjad.Duration(1, 4)
notes = [abjad.Note(pitch, duration) for pitch in range(8)]

There is more to it, but you can see how easy it is to create an ascending chromatic scale of quarter notes.  Adding time and key signatures is a tiny bit more complicated, but the examples work through all of that as well.

tl;dr: Abjad and Lilypond are fantastic tools that let you create beautiful engravings of your musical ideas.  Strongly recommended!

Wednesday, December 18, 2019

Toward Better Doctor Patient Communication through Normalized Test Results

I was recently visiting an ill friend in the hospital.  The Doctors would come in occasionally and tell him that his INR was such and such, and his Hemoglobin was so and so.  Now my friend has been dealing with his condition for some time, and there were numbers that he understood, but for many of them I had no idea what the number meant, whether it was high or low, and if it was high or low, how much of a concern it was.

While I was sitting in the room, it occurred to me that a standard system for communicating the numbers could be set up.  The idea briefly is that every number would be Normalized for the particular patient, at least so far as to account for age, weight, gender and so on.  A normal result would be 100, and anything between 90 and 110 would be ok, or cause for very little concern.  Up to 120 and down to 80, needs attention.  Above 140 or below 60, very serious concern.

It is already a common practice to include this sort of information with lab results, the (almost meaningless) measured number will be given, and then a color code, or the words "high" or "low" appended as necessary.  If normalized numbers were used instead, all of this would be unnecessary, and communication would be much improved.

It is true that many people have learned the meaning of various numbers.  I was told that Diabetics for example, are very familiar with the blood sugar numbers, and know immediately what the reported number means.  Likewise we all learn early what a normal temperature is, and what a fever is, though it is interesting that Fahrenheit wanted his scale to be something like what I am proposing, where it would be obvious if you had a fever, because 100 was the normal temperature.

Apparently his methods or apparatus were insufficient, and we therefore have a normal temperature, as measured in degrees Fahrenheit, that is almost 100, but far enough away that 100 is a mild fever.

My proposal would require some re-learning, in that 100 would be, as Fahrenheit intended, a normal temperature, but we could see a number of 104 as a very mild fever, rather than a pretty severe one as now.  It would not be until an indicated 120 or so that a fever would be indicated, as one standard deviation above the mean.  I'm not an expert in any of this, but my understanding is that a temperature below normal is is more concerning that one above, but a normalized scale would take care of that, as 80 would be one standard deviation below normal, whatever measured temperature that corresponds too.

In truth, for temperature we perhaps don't need this, but it is a good example for how the numbers would map, precisely because we are already familiar with it.

One final thought: it would be wise to have a convention for using these numbers, perhaps prefixing them with N both in text and speech, as in "Your bp is N100/100", to let someone know it is exactly normal.

Disclaimer:  I am not a physician,  I have not yet done all the work to build this into useful system, and I have not engaged a large number of people to determine if they also think it would be helpful.  My lovely wife thinks it is a terrific idea, but she is perhaps biased.

Friday, October 05, 2018

Published Academic Research is Worthless

An Economist and a friend are walking together.  They see a $100 bill on the ground.  The Economist looks at it, and keeps going.  The friend asks "why didn't you pick that up?", and the Economist replies "If it was a real $100 bill, someone else would have picked it up already".

That is a very old joke, and it is (I suppose) a reference to the Efficient Market Hypothesis.  The underlying economic principle however is no joke, and is, I suggest, generally applicable.  How can we apply it to determine the value of Published Academic Research? 

As it happens, the United States conducted a Natural Experiment in this area, between the years of 1976 and 1998 (end date approximate).  Before 1976 Copyright in this country was governed by Common Law.  The general rule was that creators own their work, but there was a large carve out, called Work for Hire, which granted employers ownership of creative work done by employees whilst on the clock.

There was an exception to the exception, for University Professors (and perhaps others). The Teachers Exception granted ownership of materials produced by Professors to the Professors themselves, even though they were working at a University when they created it.

The Experiment began with the 1976 Copyright act, which codified and replaced the Common Law rules.  In particular it codified the Work for Hire rule, without including a Teacher's Exception.  There is some question about whether Congress pondered long and hard, or even at all, before eliminating this rule, but there is really no question that the plain language of the Statute did eliminate it.

When the Congressional History is unclear, we must look to the plain language of the Statute

That is putatively a Canon of Statutory construction, though it may be the wrong way 'round.

In any case Congress in a sweeping gesture granted to each University in the United States ownership of the published work of every Academic working in that University.  What did the Universities do?


If Congress had granted them ownership of large swathes of valuable property, what would they have done?  Presumably they would, like any non-Economist who saw a $100 bill on the ground, pick it up.  On the other hand, if they were handed title to a vast expanse of burning tires, they might very well look the other way.

Now you could argue that Universities were loathe to annoy their Faculty by asserting ownership, and thereby overturning many years of precedent.  However there are about 5,300 colleges and universities in this country, and it is improbable that none of them would be willing to take that risk, if there was a payoff.

Indeed, if you are familiar with the approach of a University towards Patents issued to their faculty, the difference will be immediately obvious.  Spoiler alert: they aggressively assert ownership, and defend their legal rights to this valuable Intellectual Property.  As they should!

Quod Erat Demonstrandum

If you are interested in the legal history I set out, you should look at this excellent article from BYU.  It was the source of my legal summary above, though please don't blame them if I got it wrong.

If you are wondering why I would bother writing this up right now, you might look up "replication crisis", or read a bit about the latest hoaxing of an academic journal.

Finally, if you are wondering where 1998 came from, it is the year the DMCA was passed, which may have restored the Teacher's Exception, if you squint when you read it (see the BYU article for more).

Monday, February 05, 2018


Several years ago, when I was living in the Bay Area, I got my Ham Radio license.  At that time I got a Yaesu VX-5 handheld, and would occasionally use it to hit the repeaters in the area.

After several years of  neglect, I got a Jeep this past fall, and decided that a mobile radio would be a good backup to my cell phone, especially because NM is a big state, and there are a lot of places without coverage.  The geography of NM is good for Ham radio though, since there are plenty of tall mountains here, which are not only pretty to look at, but make great places for an antenna.

I got an Icom 4100, for a couple of reasons.  I am not too embarrassed to admit that one of the reasons was that it is the only radio I could find that can actually be controlled by an iPhone app.   The app is easier than the somewhat small and cryptic control head, especially for D-star operation.  However, if you want to use the near repeater search function, you do have to work out the UI of the actual radio.  It is not so bad, once you realize that short press and long press do something different on several of the buttons.

There is one major annoyance about the radio, and that is that it does not do APRS.  Given that it has built in GPS, and a digital mode, it should have been trivial for Icom to add it, but they did not.  APRS has some features that are very handy, including position reporting, and even texting.  NM has an extensive APRS network, and I want to be able to use it from my radio.  Fortunately, I did figure out a way to do that, as I will detail in another post.

Finally, as you have perhaps guessed, KG6JCA is my call sign, and you might hear me on D-star or 2 meters sometime.

Saturday, December 09, 2017

Male Circumcision is a worthwhile public health measure.

Male Circumcision is a worthwhile public health measure. There is some argument over the relative value of it, but if your culture or religion suggests it, there is no reason not to perform one. You might hear some of the following myths about circumcision, which I have followed with the actual facts.

Myth: Circumcision reduces sexual pleasure
Fact: The best studies done on the subject have found no reduction in the ability to have enjoyable sexual relations, compared to uncircumcised men.
Myth: At a Bris, the Mohel performs circumcision without anesthetic
Fact: Traditional Jewish circumcisions use a very safe and effective method of reducing pain in infants. See: http://www.usamohel.com/anesthesia-for-a-bris and also this WebMD article

Myth: The CDC’s support for circumcision is due to pressure from religious advocacy groups.
Fact: There are substantial reasons to circumcise infants, many of which are detailed in this article: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5478224/#B6
The reasons include, reduced lifetime risk of Genital Cancer from HPV, and reduced risk of HIV infection. It is also worth noting that while other national medical associations do not evaluate the benefits as greater than the risks, there is no association anywhere, even in countries with very low rates of circumcision, that bans the procedure.

Myth: The CDC only recently added STD prevention as a reason, it is just a pretext.
Fact: As long ago as 1855 it was noticed that circumcision dramatically reduces the incidence of syphilis.  While Dr Hutchinson's mathematical methods have been criticized (not surprising since modern statistics wasn't invented until some years later), current research supports his findings: circumcision reduces risk of syphilis and chancroid.

Myth: Circumcision is unnecessary, regular washing gives the same benefits
Fact: As indicated by the articles linked just above, circumcision has substantial effects in reducing STD transmission.  While the use of a  condom is also an effective barrier to disease transmission, safe sex practices are not always followed by everyone, but a surgical solution will always be there.  Of course, if you do choose not to circumcise your son, you should be sure he is educated on proper care.  The HPV vaccine is probably also a good idea.

Myth: If you support Male Circumcision (MC) you have no right to criticize Female Genital Mutilation (FGM)
Fact: FGM covers a variety of practices, none of which have been found to provide any health benefits whatsoever.  Some FGM practices involve the removal of the clitoris, which is a highly sensitive organ, critical for sexual pleasure.  This is completely unlike MC, which has no effect on sexual pleasure (see Myth 1, above).

Disclaimer: I should not need to say this, but just in case, you should know that I am not a physician. I wrote this based on a fair amount of internet research, and that is it.  If you have any questions or concerns about your health,  or your child's health, you should consult a qualified medical practitioner.

Friday, August 18, 2017

From VR to 3D printing with Google Blocks

Oculus Rift + Google Blocks + 3D Printer


There was some discussion that Google Blocks, which is sort of a 3d MacPaint if you will (or if you understand me, if you remember that far back, etc.) is not suitable for generating files to 3d Print.  In fact, it is relatively trivial.

Once you click the save icon in your scene, a folder with a randomly generated name will be created in the Blocks directory in your Documents directory.  Inside that folder you will find two files named Model ... one is a .gltf file and the other is a .obj file.

I use Slic3r to prepare 3d objects for printing, and have usually used .stl files (from OpenScad, not that it matters) but Slic3r is perfectly happy to open a .obj file as well.

I have only printed a couple of objects, but I can verify that it is doable.  If you are interested in trying it yourself, I will only make a couple of suggestions.  For the base of your object, if you want one, it is best to use the grid option in Blocks to be sure that the object you choose (I used a cube to start, then tweaked it to suit) is oriented such that it can be made to sit flat.  In Slic3r I found it necessary to do a 90º rotation around the X axis, after importing the object.

You may also find that the object starts out super tiny, and you need to enlarge it quite a bit before printing.  I have an object that looked reasonably large in the Virtual world, but I needed to enlarge it 30,000% and it still printed out small enough for me to hold in my hand and enclose in my fist (not comfortably though, there are a lot of corners from the cubes I built it with).  It was so tiny to start with that I could not see the grid that Slic3r generates to orient you.  The grid lines were further apart than the size of my screen ...

Why should I care?

I thought it was pretty cool, but maybe you feel differently?  Putting on a headset, entering a virtual world, using tracking devices in your hands to select and manipulate virtual tools, tools that enable you to construct complex shapes ... all that is cool enough.  However, to then take off the headset, run a few more tools, set up your printer, and in a few hours (or several hours, depending of course on the size of the model) you will have a real thing that is a pretty close copy of what you built virtually.  It certainly feels more like living in the 21st century than a lot of other things I do every day.

A small gripe

It bothers me a bit, as a certified Apple Fan Boy (though a somewhat disgruntled one), that I have to use hardware from Facebook (they bough Oculus of course), and software from Google, running on a Microsoft Operating system to do this.  I do run Slic3r on my MacBook Air (it sits near the the 3d printer, and the built in SD card reader is convenient) but it does seem Apple has some catching up to do, at least in this arena.

Two objects

Monday, June 26, 2017

Drummer from Another Mother -- Moog DFAM

Experience and Object

They say that it is better to buy experiences than objects, because they are more meaningful, and ultimately make you happier.  But what if you could buy an experience that granted you an object?  And what if that object in turn could enable you to create new experiences? How great would that be? This experience and object start with


it, which is done in two four hour workshops.  A MoogFest Engineering pass gets you a VIP pass to the festival, and also access to the workshops during which you are able to put together an unreleased synthesizer.  Last year it was the Brother From Another Mother, to accompany Moog's commercially available Mother32 syntheisizer.  This year it was a Drum synth/sequencer, called the Drummer From Another Mother, or DFAM.

When I say put together, I should be more clear.  If you have done other DIY projects that include putting in resistors and capacitors, trimming leads, mounting sockets for Opamps and so on, this is not that.  The board is already populated with all electronic components, which is just as well, as there are a lot of them, all surface mount.

The work you do is soldering the jacks, switches, pots, and headers.  Then mounting the panel to the board, and affixing the various nuts, washers, and knobs.  It is not a tremendous amount of work, especially if you are handy with a soldering iron.  Even if you are not, as a couple people in my group were not, the staff on hand will help you through it.  Speaking of which, the 


were excellent.  I think they were all Moog employees.  Steve, who also designed the DFAM, took the leading role, demonstrating the device, going over the various features of it, and even at the end giving us a bit of a tour of the schematic.  He also told us about how it began years ago as a Word doc, which did not completely describe what became the DFAM, but did include several important bits, including a feature I love, the bipolar EG amount knobs for the VCO and VCF.  There were other folks who helped out at different times also, from bringing more solder when it was needed, to giving advice on the easiest way to get things mounted.

At the end of the workshop we all wired our DFAMs together to make a giant 20 strong electronic drum orchestra.  Steve coordinated us into different groups, I think I was a snare or a tam.  Anyway, the result was pretty spectacular.

I did not record that, but I have used the DFAM for a couple of


including one created because my flight back from Durham was canceled.  I had the chance to work with it in an airport hotel a bit. since I had brought my laptop and an audio interface with me.  This is what I came up with: DFAM in NC.

Since adding it to my studio I have done a lot of recording with it, but I've only put one more thing online, this youtube video: DFAM and Vortex.  The Vortex by the way is a real thing, an effects box made by lexicon in the 90s.  I got mine super cheap from Music Go Round.  I think it was cheap in part because the previous owner had somehow managed to partially destroy the rack ears.  How is that even possible? Anyway, I have a sort of love for that device, it is so bizarre and the "morph" function is quite unusual.

I think between the two demos above, you can get some idea of what the machine is capable of, though I did not even scratch the surface of what you can do with some patch cables, and some other gear.  It definitely plays well with others. You can find a number of other videos online.

I could go on and on, I suppose but in 


I will just say that I booked an Engineer ticket for Moogfest 2018 within days of getting home.  Looking forward to another great festival, and another cool gadget.