Author: Thomas Townsley

  • Running Euterpea on macOS ARM64

    Running Euterpea on macOS ARM64

    I’ve recently gotten back into writing Haskell and exploring the relationship between functional programming and music. You may have come across The Haskell School of Music and thought about giving it a whirl yourself. The problem however, is that Euterpea is quite old at this point and getting it up and running on macOS in 2025 can be non-trivial. After spending much of the day debugging and getting Euterpea working on my machine I thought I’d leave up my working process for posterity.

    The Problem:

    Euterpea relies on the PortMidi library in order to get playback functionality. PortMidi hasn’t been updated in a long time, making it very hard to install Euterpea on macOS. My steps assume you already have GHC and Cabal installed.

    Step 1. Download and Patch Port Midi

    cabal unpack PortMidi
    cd PortMidi-0.2.0.0
    vim PortMidi.cabal

    Scroll down to where it shows cc-options: -msse2 and delete that line. It’s a compiler flag targeting x86 compilation, which we don’t want since we’re using ARM64.

    Now fix the library code. Replacing all NULL with 0 for MIDI reference types which are unsigned integers, not pointers, will bring things up to date:

    sed -i.bak 's/= NULL;/= 0;/g' portmidi/pm_mac/pmmacosxcm.c
    sed -i.bak 's/== NULL/== 0/g' portmidi/pm_mac/pmmacosxcm.c
    sed -i.bak 's/!= NULL/!= 0/g' portmidi/pm_mac/pmmacosxcm.c

    If that works you should be able to successfully install PortMidi:

    cabal install --lib

    Step 2. Download and Install Euterpea

    Once PortMidi is patched it’s time to download the latest version of Euterpea (at the present time it’s 2.0.8)

    git clone https://github.com/Euterpea/Euterpea2.git

    Now we need to point Euterpea to the custom-built PortMidi dependency. To do that you make a cabal.project file:

    cd ~/Euterpea2
    cat > cabal.project << 'EOF'
    packages: .
              ~/path to your/PortMidi-0.2.0.0
    
    EOF

    Now within the directory root install Euterpea:

    cabal install --lib

    If no build errors occur you should be able to verify the library can be imported:

    ghci
    > import Euterpea
    > play $ c 4 qn :+: e 4 qn :+: g 4 qn

    However odds are nothing will play. You will need a synth backend for any sound to play. For my machine I got fluidsynth to work.

    Step 3. Download and Install FluidSynth

    brew install fluidsynth

    FluidSynth just takes a soundfont and makes itself available for Euterpea to use. There are tons of free soundfonts you can download at Music Artifacts. After you download a soundfont you like, open a separate terminal and start start fluidsynth with it:

    fluidsynth yourSoundFont.sf2

    Now try running GHCi again and you should be able to hear notes being played:

    ghci
    > import Euterpea
    > play $ c 4 qn :+: e 4 qn :+: g 4 qn

    That’s it! Hope this helps save someone some time!

  • Failure and Delight as a Guide Towards Meaning

    Failure and Delight as a Guide Towards Meaning

    The other evening I took a hot bath. As I moved my forearm at the transition zone between dry skin and hot water, I remembered a line from the Heart Sutra, “The five senses are completely empty in nature.” It’s clear enough we understand the world through our sense organs be it our tongue, eyes or skin, but how often do we truly appreciate that? If you touch a table near you, sandwiched between your hand and the table is your sense of touch. The bath was pleasant because I’m human and not say, an oceanic snail, which would not find it so delightful.

    If you follow the existentialist bath down the drain, what happens to ethics and what it means to live a meaningful life? Should we just take baths all the time? (yes.) What about the snails? Can we judge lions? Most of us would find a female lion ripping apart a yak at least somewhat appalling, but for the lion, according to her senses, she’s achieving a great good. If lions could communicate with us, they would probably say killing yaks is revered much like we revere those who create fine works of art. What’s going on here?

    What is “delightful”, what is “good”, and how human meaning is derived from human sense-based notions are the area Abraham Maslow tried to resolve in his lifetime. In his book Towards a Psychology of Being, he brings up a clever German expression which encapsulates this nicely: Funktionslust which translates to, “A sense of joy or well-being an animal (including a human) gets from doing that which it is meant to do.”

    Those who have heard of Abraham Maslow are probably most familiar with Maslow’s Hierarchy of Needs. In essence, the hierarchy of needs indicates that we humans go through lower levels of satisfying our basic needs until we are ready to aspire towards something higher until we self-actualize. We go from being hungry for food to being hungry for meaning and deeper fulfillment.

    One problem I have with self-actualization today is how co-opted it has been by market forces in order to sell self-actualization – be it through self-help courses, lifestyle type products – and so on. If it is something we need then the market attempts to sell it. It’s by this process, as has been said recently, that “capitalism absorbs its own critiques.”

    But, as Maslow puts in Towards a Psychology of Being, the aim is much more self-contained and immaterial:

    “[Those who self-actualize] are the laws of their own inner nature, their potentialities and capacities, their talents, their latent resource, their creative impulses, their need to know themselves, and to be more and more aware of what they really are, of what they really want, of what their call or vocation, or fate is to be.”

    If we are to live a meaningful life – one that is beyond simple survival or pleasure, what do we need to do to figure out what we really want? The key is in the wording “to be more and more aware…” We simply do not start out knowing and we spend our whole lives reshaping this awareness. I’d like to relate a quick story that happened recently which greatly shaped my understanding of what I want.

    Last weekend, I entered a mandolin contest. I’d spent a month in preparation for it deciding to tackle a difficult piece most people are familiar with, Scott Joplin’s The Entertainer. I learned the full thing note for note on mandolin and so did my friend and fellow Resonaut, Troy on guitar. We meticulously planned it out. The prize for first place was $500 and I was rubbing my hands with assured victory. What I didn’t consider was who my audience (and judges) would be: bluegrass people. Everyone else in the contest played songs the judges knew. They just played fast and clean and didn’t aspire to the heights of what I’d done.

    In the end I didn’t even place. I was crushed and thereafter spent several days in real despair. “How could I have worked so hard for no one to see or appreciate what I did? Don’t they know I’m great?” rang in my head incessantly. I did not make excuses for myself, cry foul-play, and didn’t try to simply push those feelings down because there was a deeper reason for my pain. Underneath a simple contest failure was a deep misunderstanding about who I thought I was.

    I was walking around my entire 18 year mandolin journey wanting people to believe I was great and believed that winning a contest would prove that. There amid what was truly meaningful to me, the pursuit of the sublime in music, was something that had to go: needing people to believe I was great. One viewpoint would be to say “well do X and Y differently next time and play what the judges want in order to win.” But there are times when you shouldn’t get up. That can be hard when an activity that is so close to what is meaningful is not meaningful. When the pain is worth it, we know how to get back up. Maslow puts it best,

    “The answer I find satisfactory is a simple one, namely that growth takes place when the next step is subjectively more delightful, more joyous, more intrinsically satisfying than the previous gratification with which we have become familiar or even bored, that the only way we can ever know what is right for us is that it feels better subjectively than any alternative. The new experience validates itself rather than by any outside criterion. It’s self justifying and self-validating.”

    Having spent a while reflecting on my defeat, I believe I have a deeper sense of where I want to grow next. I hope this is helpful and provides some context for someone going through something similar – whichever art they aspire to. It’s worth the struggle.

  • Alpha Release is Here

    Alpha Release is Here

    Sometime in the Fall of 2020, I started to lose my mind. Those who know me understand this is not an uncommon occurrence. Going back through my diaries to find the exact “day it happened”, I see the thoughts of a young man struggling to make his mark in the world – to synthesize his many skills, talents, and interests into something beautiful – and useful.

    On one hand, he understood he was an artist at heart, dedicated to using the mandolin to convey his ideas. On the other, a lifelong habitual “tear it apart and see how it works” type. For a few years prior, he’d been exhausting himself at various attempts to merge these hemispheres: painting with guash in grid-lined laboratory notebooks, writing LISP and C programs as if they were occult spells, composing songs in a type of music notation that used grid paper, etc. The I-Ching, psychics, and astrologers were all consulted but to no avail. All of these diversions did not end his problem. He was looking for his Philospher’s Stone.

    Then one night he decided he was unhappy with mandolin pickups. He decided to make a drawing: F-hole shaped foam inserts with piezoelectric filaments buried within them. The idea being, you could shield the feedback noise from entering the sound chamber. Another drawing was made the same evening. “Why use piezos when they aren’t feedback resistant?” So he drew what appears to be an electromagnet clamped onto the bridge with a volume adjuster. Perhaps he thought, “this will be easy I’ll have this done in no time!”

    First drawing
    Second drawing

    Time would prove otherwise. But before him now was a synthesis of the technical and the romantic – had he found what he was searching for? What he drew that evening would not be the recipe for his Philospher’s Stone, but now he knew where to find it. I’m immensely proud that young man stuck with it for so long. Five years later, I’m finally able to bring the first version to other musicians and using it in my own work with The Resonauts.

    Many folks I’ve talked to don’t really see why pickups are so important, especially mandolin pickups – “Good luck with that.” They are perceived as a means to an end and nothing more. This is wrong on many levels. Pickups connect what is within the artist to an audience – they extend the golden ladder of musical forms to large crowds of people. Even more, what an artist is capable of expressing is also highly dependent on how they feel on-stage. Nothing will ruin a mood faster than feedback issues. Everyone, including pickup manufacturers, seems to take this for granted.

    The fact that the most popular mandolin pickups are the exact same brand and model as they were when I started playing 18 years ago is unacceptable. There has to be something better, and in fact, I know there is. Right now I’ve selected mandolin players in the Nashville area to test drive them and check for any issues before the official beta release.

    If you’re interested, join the wait list and be the first to know when the pickups are out!

  • Gaglio’s Double Winding Patent

    Gaglio’s Double Winding Patent

    I found this patent recently and was impressed with it’s simplicity. Filed in 2001 by Giovanni Gaglio, it appears to be a magnetic pole piece with two wires wrapped around it, rather than one. How is this a novel advancement? Gaglio explains the issue his invention solves:

    In particular, it has been found that output level on one hand, and fidelity and capacity to reproduce an extended frequency range on the other hand are contradictory properties. In fact, by increasing output level in volts of the pick-up device, gradually the capacity to reproduce high frequencies is lost, whereas an extremely accurate pick-up device, able to reproduce a wide frequency range cannot offer an adequate output level.

    Electromagnetic pickups are just that – electromagnets: a magnetic material wrapped many (usually hundreds) of times with very thin copper wire. When an electromagnet is placed underneath metal strings, the strings become partially magnetized and are effectively a part of the magnetic field. As strings vibrate this disturbance causes a momentary collapse in the field and frees electrons to pass down a circuit. That phenomenon is called induction.

    Electric generators follow this same principle: pass a magnet over copper wire to induce voltage. Increasing the number of turns of wire and its respective gauge, produces more voltage. Nikola Tesla’s Dynamo Electric Machine took this principle and by spinning magnets of opposite polarity, was able to induce large voltages with sinusoidal uniformity, and thus created alternating current.

    US390414A Tesla’s Dynamo Generator

    With the phenomenon of induction in mind, what does Gaglio mean that “increasing output voltage hurts the ability to reproduce high frequencies”? As the number of windings increases around the magnet, it effectively increases the resistance of the pickup itself. Higher resonant frequencies and overtones have far less energy to induce change in the magnetic field and travel through this increased resistance and so, are attenuated. It’s for this reason that many electromagnetic guitar pickups targeting acoustic guitars sound way too muddy from the low end, and do not faithfully reproduce the acoustic “shimmer”.

    Figure 1 from Gaglio’s Patent Showing a typical pickup, although the copper wire is wrapped around magnets individually.
    Figure 2 shows a more simplified view. The copper wire is wound around an individual magnet with it’s leads terminating at a positive and ground node.

    So what is Galgio’s solution here? It is remarkably simple but not obvious. Figure 3 shows a doubling of the wire in figure 2, one wire being solid (lead 4) and the other dashed (lead 5) to distinguish them. Notice that the wires do not have continuity but remain unconnected (see points 7 and 8 in Fig. 3). How is electricity supposed to flow?

    We are left with the briefest explanation and no further elaboration:

    The continuity in the transmission of signal between lead 4 and lead 5 of the double-lead winding is obtained through the capacitor ideally as the result of the amount of parasite capacities that are generated between each turn of lead 4 and the one of the lead 5.

    By “parasite capacities” he’s referring to the property known as parasitic capacitance: a usually undesired side-effect where two different charge carrying transmission lines are close enough in proximity to one another that they form a capacitive coupling. As with any capacitor, signals can flow through this coupling and that’s exactly how the circuit in Figure 3 is completed.

    The “output voltage vs frequency response” issue is fixed because the path taken from lead 4 to lead 5 is through the parasitic capacitor formed across the two windings, despite ends of the windings being unconnected. Thus, you can wind a lot of wire to get a higher output voltage and still get the higher frequencies.

    Sadly, I’ve been unable to find any examples of Gaglio’s concept, so it’s difficult to say whether it would work, or if the corresponding amount of wire turns would have to be so high, it didn’t make such an arrangement practical.To say there is a lesson is probably quite unnecessary and pedantic, but I’d recon it would be something like:

    “There’s always another path you can take.”

  • Design is a Negative Feedback Process

    Design is a Negative Feedback Process

    I’m kicking myself for not having read Henry Petroski’s, The Evolution of Useful Things sooner. Since reading, I’ve focused much more on small iterations and attempting to marginally improve my designs. My goal at the end of each day is to have a prototype that works and is slightly better than it was previously. Whatever is left wanting, I attempt to fix next. The result is a more fluid (and fun!) process than trying to mentally conceive of a working concept all at once. I’m also finding that I’m getting what I want out of a design.

    The main premise of the book is this: Conventional wisdom says “Form Follows Function” – more easily understood as, “the shape of an object is determined by it’s intended use.” Was the paperclip created in the shape it was because the designer knew ahead of time it had to be that shape? Petroski argues we as a material culture view designed objects in this way when in fact, “Form Follows Failure.” An object’s shape is essentially the outcome of iterations of failed attempts to achieve the desired function. An object’s shape is merely a by-product of when things finally go right. Petroski points out:

    “They do not spring fully formed from the mind of some maker but, rather, become shaped and reshaped through the (principally negative) experiences of their users…clever people in the past, whom we today might call inventors, designers, or engineers, observed the failures of existing things to function as well as might be imagined.”

    Inventing then, is not some erudite task for intellectuals with a background in calculus. It is more commonly the result of regular people who work simply in a domain where they have some knowledge and, having perceived some failed function in a tool (or wishing the tool existed), are so annoyed that they actually choose to do something about it. The inventor’s chronic need for better is thus society’s gain.

    “Sewing Machine” by John Tercuzzi.

    As a chronically annoyed person, I believe this urge for advancement in one’s art faces a new challenge today: We live in a period of time where “better” can be purchased relatively quickly. This can lead to what I call “design by purchase.” For years I would find myself waiting around for weeks for that new part to come in the mail, only to find it didn’t pan out the way I’d hoped. Now, by allowing the work to evolve by making a small, marginal improvement today, creativity finds a way to make do with what materials are laying around and, in the process, this keeps the real requirement in view at all times. This principle objective, according to Petroski, needs to be expressed negatively:

    “Design and invention are a fundamentally negative process.You do not have to satisfy all requirements and usually some requirements are incompatible. It is better to weed out irritants over time through each successive iteration.”

    Finding the real requirement worth satisfying is essential here. A common slippery slope is something to the effect of, “I need a widget that does X. Ok, so I’ll need to machine the widget out of material Y. Ok, so I’ll need to purchase a machine capable of doing the routing. Ok, I’ll need a dust collector for the machine.” and so on…

    But this will usually stray from the original ask. A better approach is, “Why do I need a widget that does X? Is there another way to achieve the same result without improvements to my manufacturing capability?” What once presented as a real requirement can often prove to be a red herring. And trust me, red herrings can last years.

    Sometimes though, the only answer is to obtain a deeper knowledge of the art or to improve manufacturing capability. Seemingly simple devices of yore can strike you as odd it hadn’t been invented sooner. Underlying the creation of any object is an interplay of materials science, manufacturing capabilities, and some party having made a degree of investment in those capabilities. For the paperclip, advances in wire bending in the late 1800’s such that the wire would not simply unravel, but instead keep it’s shape were critical to the success of paperclips coming to market. Petroski writes:

    “Thus understanding the fundamental behavior of materials and how to employ them to advantage is after a principle reason that something as seemingly simple as a paperclip cannot be developed sooner than it is.”

    And once it is possible to manufacture the object, what does better look like? I’ve read countless patents on musical instrument pickups dating back to the 1930s. Each inventor must have had some feeling that what she created was indeed the “best.” Why else go through all the trouble? For Petroski, being the “best” isn’t the point, nor is it what produces a successful design:

    “As with the Gem paperclip, it seems the design that ultimately wins out is the one that succeeds at getting the requirements right and does the job satisfactorily but does not need to be ‘perfect’ or ‘best’, especially if it’s form is a pleasing rounded and natural appearance that gives it a distinctly human feel in view of it’s competition.”

    “But surely Mr. Shakespeare, two heads is better than one” by Will Dyson

    So don’t aim for “best.” The takeaway from The Evolution of Useful Things is to just make something slightly better. It is to discover true requirements by expressing needs in negative terms based on what is currently unsatisfactory. Do not aim for perfection. Finally, if nothing leaves you wanting, concentrate on making it more human. Therein an invention becomes what it was always meant to be, not a merely tool, but a transcendent object of desire – the product of an inventor’s love and will made visible in the world.

  • DeArmond’s “Pickup and Volume Control” Patent

    DeArmond’s “Pickup and Volume Control” Patent

    Perhaps no one in the 20th century thought more about the method of attachment to arch-top bridges than Harry DeArmond. A prolific designer, inventor, and musician, he is credited with inventing the first commercially available attachable guitar pickup in the 1930s. Amplification of stringed instruments was then in it’s infancy. The instruments that did have pickups installed were integrated into the body, like a lap steel.

    Much of the instruments owned and played were at the time of course, only acoustic. When money was sparse, how was a musician to be heard on the increasingly loud stages of the jazz era? DeArmond’s designs appear to seek the preservation of what was great about the acoustic instruments of the period while also allowing them to be heard. Being a simple, cost-effective add-on for the musician rather than having to outright purchase a new instrument, it’s no surprise these floating pickup designs are still in use by jazz artists today.

    One of these designs appear to target the mandolin player. US Patent No. 2455567A shows a Honer-esque A style mandolin with a floating electromagnetic pickup. Unlike his famous “Monkey-on-a-stick” where the “stick” makes a touch-less wrap around the player side of the bridge, the base of the stick here braces a fork on the player side bridge adjustment screw. He refers to this as “a bifurcated supporting bracket, the two ends of which are adapted to slide under the knurled nut…”

    I haven’t been able to find any surviving examples of the stabilizing fork protruding from the bridge. Perhaps this design was never used in production, or given the fact a rod can be inserted from both ways into the coil casing, the rod was preferred to extend from the neck down, or the classic bridge wrap around worked better, the other rod shaped being discarded. Examples of these methods do survive.

    DeArmond Pickup with “stick” extending from above
    Classic “Monkey-on-a-stick” bridge wrap around

    Another interesting find is in Figure 5, which shows a very nice cutaway heel on the player side – no doubt to prevent the playing hand from brushing against the electromagnet. My earlier designs included this slope, almost to the same angle and extent as DeArmond’s! Convergent evolution.

    DeArmond’s sloped heel
    An earlier “DreamSnake” design of mine with a similar slope

    August 7, 2025 Update:

    I stumbled upon an example of a stabilizing fork being used at present in the Shadow SH 928. It surprisingly appears situated above the adjustment wheel on the treble side, implying the strings have to be slack before the fork can be inserted:

    Shadow SH 928 with a stablizing fork on the bridge

  • The Nature of Suffering and Choosing Good

    The Nature of Suffering and Choosing Good

    The first of the Four Noble Truths handed down by the Buddha is dukkha, roughly translated into english as “suffering”. In the Buddhist view, when reality is seen correctly, a practitioner will understand the inescapable nature of suffering or “dissatisfactoriness” in life. Knowing that suffering is inescapable is a step towards nirvana and out of suffering.

    M. Scott Peck illustrates the acceptance of suffering well:

    “Life is difficult. This is a great truth, one of the greatest truths. It is a great truth because once we truly see this truth, we transcend it. Once we truly know that life is difficult-once we truly understand and accept it-then life is no longer difficult. Because once it is accepted, the fact that life is difficult no longer matters.” – M. Scott Peck, The Road Less Traveled: A New Psychology of Love, Traditional Values and Spiritual Growth

    It isn’t hard to observe this truth. Going for a walk in the forest reveals a menagerie of bugs and plants killing each other for food and survival. There does not seem to be an implicit “good” or “bad” in nature – a nature we humans are a product of. Why then, should we be good at all? Pondering this, I came across Beyond Bumper Sticker Ethics by Steve Wilkens. It provides a refreshingly approachable overview of ethical systems, their history, and how they attempt to answer what it means to be “good” and why we ought to.

    Most of the systems covered attempt to create a universal foundation for ethics based on human reason. However, “reason systems” cannot answer well for all situations. There’s usually a paradox lurking somewhere. Kant’s Categorical Imperative implores you to act only in a way that the action should become a universal law. This means you cannot lie to save someone’s life, as most would agree “Do not lie” should be universally adopted.

    Transcendentalist views try to address the flaws of reason – either disregarding or qualifying reason with another basis for human motivation such as love or the reception of divine information. These efforts however, tend to devolve into a kind of relativism. After all, who can define “love” in a universally accepted way?

    Wilkens makes a good case for why it’s worth erecting an ethics out of nature’s ambiguity, even if that ethics is inescapably human:

    “The language system our minds use to process information seems to match, in some way, the language of the natural world so that the data received is understood. Without some form of compatibility between the logical structure of our mind and the logic of the universe, it would be impossible for us to know anything about the world outside our mind…the assumption that our ideas correlate with what is “out there” is a common intuition.”

    The fact we have a cognition which can navigate and approximate an understanding of reality means we probably can and should create an ethics which itself is consistent with, and a part of nature. Wilkens points out the obvious danger in seeking out a truth for how we ought to behave, paraphrasing Karl Barth’s criticisms of Thomas Aquainas’s spiritual reason,

    Image of a dark interior of a Catholic basilica.

    To say the means by which we can discern the truth can be the same means by which we can obscure it nothing new here. But Wilkens indicates why this process of discernment is still worth it:

    “Even though I have not endorsed any specific position here, there are a number of indications that rather than giving up hope that some sort of ethical truth can be discovered, the entire process of inquiry assumes that truth is possible.”

    We are made better by the process. Better off than we have been had we never tried at all. “Better” may need a direct definition and so is the case with “good”. But we may at the very least ask ourselves what we believe “good” to be and revise it when confronted with more convincing ideas.

    In light of suffering and it’s reality in our lives, the choice to improve and become, as Thomas Aquinas would say, “All that we can be” is in fact a rational one.