Today I am preparing for an operating systems test, and writing my business idea’s elevator pitch for tomorrow’s entrepreneurship class. 

Learning about processes and threads in Linux. I’m specifically reading a lot about the fork() function and the exec() family of functions.

Updating my JS piano

I’m working on adding more features to my JavaScript piano. I was able to add two listeners so that you can play it either with the keyboard or with the mouse.

For this assignment in our web scripting class, we are to let someone alter some aspects of the piano. Since I use a colemak keyboard layout, I would like to let people alter which keys fire which notes. When I look in my switch statement for the keyboard listener I see:

/* keyboard listener to enable playing with standard keyboard input*/
document.addEventListener("keydown", function(event) {

        var note; /*used to track which note is pressed*/

        console.log(event.which);

        /* setup a switch statement for keyboard presses */
        switch (event.keyCode){
            case 65:
                note = "key_e";
                playNote(note);
                break;

            case 83:
                note = "key_f";
                playNote(note);
                break;

            case 68:
                note = "key_g";
                playNote(note);
                break;

            case 70:
                note = "key_a";
                playNote(note);
                break;

            case 71: // left thumb
                note = "key_b";
                playNote(note);
                break;

            case 72: //right thumb
                note = "key_middleC";
                playNote(note);
                break;

            case 74:
                note = "key_d2";
                playNote(note);
                break;

            case 75:
                note = "key_e2";
                playNote(note);
                break;

            case 76:
                note = "key_f2";
                playNote(note);
                break;

            case 186: // right hand pinkie
                note = "key_g2";
                playNote(note);
                break;
        }  /*end switch*/

In this program, my JS piano framework adds an event listener to the document to listen for keyboard events. What I can try is adding 10 parameters to the JS object which let the person set which keyCode should trigger an event. Then I’ll use those parameters in the above switch statement, instead of letting the switch statement look for which keyCode was pressed.

I’ll update this later after I see what happens.


Update from the next morning….
Holy shit that didn’t work. I spent a few hours pulling my hair out. Well, I don’t have hair… pulling my beard out. I tried every which way to get the note to update but it’s giving me trouble.

I was able to abstract out the note settings so that I pass in the keycode event I want the piano object to use, but I am not yet able to update that object to a different key whenever I want to.

As you see below, I can let someone pass in keycode events for a specific note or set a default keycode event. The defaults below are for QWERTY keys. You’ll see noteE doesn’t have a default parameter. I found that if I didn’t initialize noteE, then when I create a new myPiano object and pass in an initial parameter for noteE then it will take.

var myPianoObject = myPianoFramework.makePiano( { id:"pianoObj", noteE:90 } );

If I initialize my noteE to be (65||params.id), then then noteE will be set to keycode 65 and not 90, even when I create the object with the line of code above.

myPiano.makePiano = function(params) {

    myPiano.id = ("" || params.id);
    myPiano.noteE = ("" || params.noteE);
    myPiano.noteF = (83 || params.noteF);
    myPiano.noteG = (68 || params.noteG);
    myPiano.noteA = (70 || params.noteA);
    myPiano.noteB = (71 || params.noteB);
    myPiano.noteC = (72 || params.noteC); /*middle c*/
    myPiano.noteD2 = (74 || params.noteD2);
    myPiano.noteE2 = (75 || params.noteE2);
    myPiano.noteF2 = (76 || params.noteF2);
    myPiano.noteG2 = (186 || params.noteG2);

The trouble is when I want to let the user type in a new keycode event and update the javascript object. I’ve tried every manner of things that look like:

myPianoObject.noteE = 90;

or

myPianoObject.noteE.value = 90;

or

myPianoObject= {noteE:90}

…but nothing there is working. I wonder if I need to make a specific function within my javascript object that lets me update that parameter. I will keep trying.

Visual metaphor for cache memory

Personally, I need visual metaphors. To understand cache memory I constructed this elaborate system in my mind connected to Temple’s Paley library, some fictional shelves displaying photos, and the elevator down to the basement where my friend works.

The shelves(cache slots) hold boxes(blocks) and each shelf has a Tag. There’s a map pointing to where each tag is. There’s a “write policy” on the wall that says if you alter a photo, you must update main memory!” Lastly there’s an elevator (to indicate slowness) down to Main Memory where you see many shelves and many boxes. The part I had to stick in at the end is a little robot called Replacement Algorithm who keeps track of which block hasn’t been requested in a long time and replaces that cache with new data when space is needed. It’s working for me.

I first tried to do this with visualizing a Bus and passengers getting on and off, but it broke down. Unintentional dad joke.
cache

Today I am: watching Gary Vaynerchuk videos, struggling with understanding fork() & exec() & threads & processes, and writing pseudocode for my Linux shell. Last night I could not get CLion to compile anything on my Ubuntu install, and after cursing at it for an hour, I gave up and went to bed. This morning I decided coding the shell in Sublime text will make me a better programmer anyway, so that’s what I’ll do.

Working on writing a Linux shell for operating systems class