Programming languages built around the Grid

I’m curious to learn of any attempts at build some kind of “programming language” specifically for the Grid or similar grid interfaces. In other words, this would some sort of environment where you’d write a program on the Grid directly in place of a keyboard + text editor.

I’m in the process of building one myself, and would love to be inspired.

My idea is to build a toy VM designed to be used as a rhythm computer. You can sort of think of it as a inspirational smoothie of brainfuck, and prop, a proportional rhythmic notation language of mine (but minus the proportional stuff). Programming it involves creating sequences of 64-bit bit patterns (called “words” or “cells”) arranged in an 8x8 squares on the Grid, which later get parsed into opcodes in a program optimized to output rhythmic patterns. The interface at the moment splits the 128-grid in half, with the left half being a control panel, and the right half being the word editor (this hasn’t actually been built yet).

I started working on an working implementation of the VM. Here are a few code examples and their output.

These three words produce a looping sequence of “101011”, with the patterns broken into “10” and “1011”.

basic

These 6 words create a rhythmic sequence that randomly alternates between “10101010” and “11101110”.

maygate

Using some special functionality to one of the words, you can do the same thing in only 5 words:

maygate_v2

Using some special functionality, you can do a similar thing in only 3 words:
maygate_v3

I’m being a little handwavy at the moment for brevity, but I’m happy to elaborate on anything here so far.

21 Likes

It is difficult for me to wrap my head around this at my current level of maths/programming skills but this inspires me to learn.

1 Like

Can’t wait to see this evolve!

This seems to have some overlap with Punchcard maybe that can give some inspiration?

4 Likes

To be fair, I’ve hardly given any explanation. Just a few teasers. I wouldn’t dismiss your skills so quickly! My hope is to minimize the math/CS bits and streamline things to make it feel musical to work with.

75% of the “coding” as I see it now is just making rhythmic patterns like you would on a drum machine. The other 25% involves arranging/processing those patterns in interesting ways to make longer musical sequences. It is in that 25% that more programmer skills and ways of thinking come in handy. The programming stuff here involves telling the computer things like “hey, go to this section now” and “let’s play this pattern, but let’s do it backwards this time!”.

4 Likes

not sure if it counts for programming but there’s some history of “glyph” combos being used to accomplish various tasks in grid apps

but looking at what you’ve got i’m keen to see where this goes especially as a sequencer

the preliminary output you’ve shown above would be beautiful!

1 Like

as mentioned, Punchcard is definitely riffing on similar ideas with its 8-cell opcodes.

i’m also kinda inclined to look at this as an elementary cellular automata system. i think theres some interesting unexplored territory with those, as far as being able to directly manipulate binary rules and state.

4 Likes

I really like your idea even just from the visual side of things :smiley: If you have found any papers/resources about VMs specialized on generating music/sequences please link them as I am also interested in that topic. So in the examples that you have how the words are translated into opcodes? You just treat column or row as a binary number or something else? I wonder how could such interface be self explanatory without manual, maybe something like manual page where you could enter word and it would try to crudely display it name on the grid? :smiley:
And about cellular automata I agree that especially the 1D ones could be easily manipulated on the grid as their whole rules can be encoded as single 8bit number.

As you mentioned brainfuck I hope you will forgive my shameless plug, but I have written in the past sequencer based on brainfuck with few additional operators. Demo: http://firmanty.com/brain/ source: https://github.com/kfirmanty/brain-seq

1 Like

In a similar vein to prop, I also wrote a notation for generating L-systems called lsys. Both are available as ugens in sporth. These are more state machines, less VMs. The line does blur. There’s a great program called ibniz which has massively inspired me over the years. I think Viznut was also the person who first popularized these one-liner music compositions using bitwise operations.

A 64-bit word (which I call a “cell”) containing a full opcode is split up into 2 32-bit words. Visually, these words appear as two bricks stacked on top of each other. The top brick is known as the “command” word, which tells the type of command. The bottom brick is the “data” word, which stores data for the command.

Cells are grokked row by row, left to right, up to down. Here is the first cell from the first example, with the command and data words split up, and the rows labelled.

c0 10000000
c1 10000000
c2 01000000
c3 00000000

d0 10000000
d1 00000000
d2 00000000
d3 00000000

c0 of every cell tells what kind of cell it is. In this case, it is a pattern.

c2 (EDIT: not c1) of a pattern cell tells the size. This is encoded in little-endian binary, with the lowest bits on the left. It’s backwards from how you’d normally see it, but it makes more sense in my brain this way for some reason (also easier to parse). In this case, the size of the pattern is “2”.

EDIT: c1 tells the pattern to write the output signal to wire 1. Wires are how this thing communicates with audio signals.

c3 doesn’t do anything in this particular instance.

The whole data word is dedicated to storing a bitmap pattern, which can have a size up to 32. In this case, it’s only reading the first two bits of the word, making the entire pattern “10”.

I like the idea of having some kind of cell lookup, where you parse a cell and spit out what it is doing. Displaying words on the grid itself would be very goofy. Not entirely a no though. There are at least a few tiny bitmap fonts which could be suitable, and I’ve always wanted an excuse to build a message scroller. This could also be suitable for something like a norns display.

3 Likes

Thanks for explanation and reminding about ibniz as I wanted to explore this software further in the past. Just a small nitpick but if cell size is “2” in little endian shouldn’t the c1 be 010000000? :stuck_out_tongue:
There must be something in the air about L-Systems because immediately after writing my previous response I started to think what if 1D CA would be used to generate patterns but at every patterns start the rule itself would be changed by L-System? Demo is here: http://firmanty.com/lsystem-ca/ (but click at least once somewhere on site for drum sound to play) and source (but very messy, don’t judge my coding skills based on it :D): https://github.com/kfirmanty/lsystem-cellular-automata rule is restarted to init rule every 8 patterns and to get different init CA rule just refresh the site or click randomizeInitRule text in control panel on the right. The l-system rules can also be changed from panel.
EDIT: I checked lsys and really like how concise the grammar is! Now I started to think how such rule to generate l-systems could itself be generated :smiley:

1 Like

Oops! nice catch. I actually messed up the breakdown and will edit this in the previous response. c2 is the size, not c1.

c1 tells the pattern to write the signal to wire 1. Wires are ways of getting signal in and out of the machine.

c3 still doesn’t do anything.

1 Like

After studying some rosetta code, I managed to hack in some 1-dimensional cellular automata.

Here it is in three(!) cells, utilizing rule 90 to make some visually pleasing Sierpinksi Triangles.

metapattern_ca

It’s a little dense what is happening, so I’ll break down.

The program implicitly starts and runs at cell 1.

This is cell 1:

c0 10000000
c1 10000000
c2 00000100
c3 00000000
d0 00000000
d1 00000000
d2 00000001
d3 00000000

c0 tells us that this is a pattern cell
c1 tells us to write the output to wire 1
c2 tells us the size (32 in LE binary)

d0-3 is the pattern information. In this case, a single bit in the middle. Our initial state.

After cell 1 is finished performing the pattern, it goes on to cell 2:

c0 00010000
c1 10000000
c2 11111111
c3 01011010
d0 10000100
d1 00000000
d2 00000000
d3 00000000

c0 tells us that this is metapattern. A metapattern references another pattern in the collection of available cells, and dynamically applies up to 6 transformations to it. After it transforms the pattern, it treats it like a normal pattern cell.

c1 tells us which cell pattern to use. It is encoded in LE binary to use cell 1 (the previous cell).

The remaining 6 rows are used as command bytes to apply transformations. These commands are applied top-down.

c2 is the command to apply one CA state transition to the pattern. Typically transformations take up 1 row, but this one is greedy and takes up 2! The exception to the rule is why I made it look like one solid bar.

c3 acts as data to the CA procedure. It tells which rule to apply. In this case 90 (encoded in LE binary).

d0 is another byte command called “update”. It will copy over metapattern pattern data to the pattern it is referencing.

d1-3 are empty and don’t do anything.

This metapattern will output a 32-step sequence at the end of this, then go to cell 3, which looks like this:

c0 01000000
c1 00000000
c2 00000000
c3 00000000
d0 01000000
d1 00000000
d2 00000000
d3 00000000

c0 tells us that this is a jump statement.

bits in c1-3 are not engaged, so no additional caveats here.

rows d0-3 (aka the data word) are used to graphically show where to go. This VM is built to have 32 cells visualized on a 8x4 grid. In other words, this tells us to jump back to the metapattern in cell position 2.

This final goto statement creates an infinite loop, with the original pattern in cell 1 used to store the state of the previous iteration.

5 Likes

For those curious, I’ve uploaded the VM code to github. It’s written in ANSI C, using a literate programming style (a subset of org-mode I’ve been developing). As it turns out, github can render the document to HTML, making it suitable for skimming. It’s only a few days old, so things are a bit untidy in some places.

The code examples so far are being generated in this hot mess here. I’m using my 1-bit graphics library to generate PBM files, which I then convert to PNG files using imagemagick.

1 Like

I took a first stab at an interactive interface on the Grid. It makes signals that can map to sound now too! Here’s quick video where I yak and press:

Hoping to spend more time actually using the interface and trying to make something more musical out of it. I’m already discovering things I didn’t know I needed, including the “reset” button on the bottom lefthand corner that resets the playhead to the beginning.

The cool thing is that the VM up to this point should already work. All the examples I’ve made offline at this point should now be functional as sound!

Perhaps a cheat sheet is in order.

3 Likes