Thursday, January 16, 2025

David Lynch Dies, Crumpsy Madpash, My First C++ Goto

Sigh, a sad evening as I hear that the wonderful David Lynch has died. My dreams of meeting him will be confined to the dreams in which we meet.

I started today working on the Fall in Green music, a simple matter of adding the vocals Deb recorded on the 2nd of December. I found the need to delay a sound starting for a second or so. The updated (Nov 2024 version) sample players have a countdown before they play, and that could be any size, but I limited it to a mere second. I thought this was a bit mean, so today I extended it to 8 secs. There were about 6 plugins which used this.

Starting this simple programming task led me down a tunnel of wanting to update the other sample players with new efficiencies. The code used to check if a sample was there, and if so count a loop of 64 samples, each time checking if the pointer was past the end of the sample or not. I realised that I could unify both checks in some cases, dropping out of the loop rather than running the same check 64 times in a row. In other cases, the 64 loop can be needed for countdowns, but I could still drop out when needed. The code in these cases ran like this:

if (lpengine->sample)
{
    for (b=0; b<64; b++)
    {
        if (!flag)
        {
            (countdown timer, and if at zero set pointer=0 and flag=1)
        }
        if (lpengine->sample->pointer<lpengine->samplesize)
        {
            (data is copied here, pointer incremented)
        }
    }
}

The latter 'if' runs 64 times in a row, when a first fail can cause it to drop out, AND it needn't check at all if the flag isn't set - but it does need to check when the flag is set for the first time. At first I used an 'else' statement and a 'break' to stop the loop:

if (lpengine->sample)
{
    for (b=0; b<64; b++)
    {
        if (!flag)
        {
            (countdown timer, and if at zero set pointer=0 and flag=1)
        }
        else
        {
            if (lpengine->sample->pointer<lpengine->samplesize)
            {
                (data is copied here, pointer incremented)
            }
            else
                break;
        }
    }
}

Better; but I needed the data copy to take place when the flag was initially set, so for the first time in my programming life, I used a 'goto' statement to jump over the 'else':

if (lpengine->sample)
{
    for (b=0; b<64; b++)
    {
        if (!flag)
        {
            (countdown timer, and if at zero set pointer=0, flag=1, and goto calculate)
        }
        else
        {
calculate:
            if (lpengine->sample->pointer<lpengine->samplesize)
            {
                (data is copied here, pointer incremented)
            }
            else
                break;
        }
    }
}

These programming distractions took all day, but I did manage to insert the vocals into Crumpsy Madpash. At times of artistic transition, I find programming a useful reset; like bringing a 'Logo Turtle' to a stop before rotating and heading off into a new direction. Today's changes made Prometheus a tiny bit faster and more efficient.

Life is about tidying, fixing, making more efficient. Life persists because order is resilient and chaos not so. The more ordered we are, the more resilient we are. Order is strength. Chaos is weakness. Onwards we march.