Glitch after one month
Glitch is a minimal environment for making algorithmic music and live coding. It uses simple arithmetic expressions as a programming language and has only a few functions to learn, yet it allows creating some interesting music pieces.
It’s been a month since I last talked about Glitch here, but it has been a very productive time, which has totally changed my vision of Glitch and its future.
And old ox makes a straight furrow
It’s 2016 here and web is still a disappointment.
But Glitch never worked well even on the most high-end Android phones, Glitch wasn’t capable to using PulseAudio or Jack on Linux to let me play along using other synthesizer apps, Glitch even failed to play more-or-less complex music on some decent multi-core PCs!
That’s where I had to recall that I’m still a good low-level programmer and rewriting Glitch in C should not be that hard. The core of glitch — the expression evaluation engine — has been rewritten in a couple of days, covered with tests and all the memory leaks have been fixed. It’s now available here — https://github.com/zserge/expr.
I opened vim, started index.html and styles.css, dropped in mithril.js for UI components and then wrote just one big JS file — the identical Glitch web app, written in one day, using no build system and no compilers. Yes, it won’t run on some old browsers, but the original Glitch failed to run there, too, because of its slowness.
So this new Glitch-rewritten-in-C is the app that you can see at http://naivesound.com/glitch. It has the same look, the same functionality, but works much faster. That’s how old school technologies have saved a project.
The general syntax of Glitch remained unchanged, but there are some new things added.
The most important one is constants for notes and drums. These are just variables written in caps that should not be modified as they contain some useful pre-defined values. For example, to define a sequence of notes you may now write their names:
sin(hz(seq(240, C4, D#4, F4, D#4)))
Also, for TR808 drums you may not keep in memory drum numbers, you can use abbreviations — BD (bass drum), SD (snare drum), MT (middle tom), HH (high-hat), OH (open hat), RS (rimshot), CP (clap), MA (maracas):
mix(tr808(BD, seq(120,1,0)), tr808(SD, seq(120,0,1)), tr808(HH,seq(120*2,1)))
Next, sequencers now can take a pair of values for tempo — the optional first number would be the initial offset in beats. That’s how the drum pattern above could be rewritten as shown below (snare drum is offset by half of a beat from the bass drum):
I’ve also added the hpf(signal, cutoff) function. Although it can be implemented by subtracting the low-pass filter output from the original signal, I find it too long to type.
Finally, I’ve added the great delay(signal, time, level, feedback) function, which enriches sound a lot. It takes a current signal value, delay time in seconds, a delay mixer level (0..1) and a feedback amount (0..1) which affects the repetition of the delayed signal.
You can hear delay in action — try moving your mouse to modify delay level and feedback parameters.
Meanwhile, I’m working on a desktop version of Glitch. It’s a command-line app at the moment and it runs well on Linux, Window and Mac, using low-level audio libraries. I was able to make the beat and bass in Glitch and played the piano using Pianoteq at the same time without any sound lags.
But the major difference of desktop Glitch comparing to the web app is that you can use your own samples — each sample would appear as a Glitch function, samples can be grouped in folders and a function parameter can pick one of the sample variants. So Glitch is now a programmable sampler!
Also I find it much more convenient to use a decent text editor that updates the playback when I save the file, than using a browser.
I’m thinking about adding live MIDI input and output capabilities to Glitch, as well as maybe live audio input so Glitch could be used to process guitar sound or voice. Also, I can’t stop thinking about Glitch on mobile, I think that would be a nice toy to play with.
And of course I’m looking forward for the feedback from Glitch users! If you miss some sound effects or some helpful functions — please file an issue on Github or submit a pull request.
So, what would you like to see in the next version of Glitch? Or what would you like to hear in the next post?