Generate Musical Accompaniment with R
flujoo.github.io
flujoo.github.io
General comment: one reason that the R package ecosystem often feels creaky and brittle, I think, is that a lot of packages (like this one) are pretty far afield from R’s original intended uses of statistics and visualization. Here, we see the use of integers to denote pitches strung together as a vector to generate a sequence. That’s not precisely a misuse, but it’s definitely misaligned with the original vision, and trying to build things on top of that misaligned infrastructure is a potential vector of packages’ breaking and general irreproducibility.
Not sure how any of this is really relevant here. This is a general R gripe.
Explain what you mean by this. It’s a big claim without any supporting evidence.
The tidyverse is absolutely full of breaking changes. Two big ones off of the top of my head: dropping underscore functions like mutate_, and turning common column names into new function names. So in different organizations you might see two patterns:
* Monolith - everyone uses a set of R packages from 2017 or whatever (frozen in time either through MRAN or Nexus)
* Wild dockerization - one team’s internal tooling is incompatible with the other team’s, so working across teams you gotta rely on Docker a lot
Why? Cause there’s not really a good way to pin versions besides shrinkwrapping, at least in my experience. We tried Drake, but Drake itself had so many breaking changes that it gained a really bad rep (from what I hear from colleagues, haven’t used it myself). Tried renv but it was destroying some of our analyst’s setups (like, you just get a bomb icon in Rstudio). Didn’t troubleshoot it too much, kinda just gave up.
I don’t like forcing a specific vintage of packages, but I like everything else less.
The idea behind a native R solution is that it is far less likely to be deprecated.
By contrast, R has the occasional but rare installation issue, and almost all the common ones are solvable in a few minutes with a re-install.
I think for large software projects where dependencies could be an issue, especially long term, R might not be the best choice.. for now anyway.
I feel some of your pain on the tidyverse front, but for that reason I stick mostly with fairly common functions and avoid exotic new ones. Even if I do venture into new ones, I comment them so I know precisely what's going on so in the event of a refactor a few years' down the track I'll be fairly safe. With R there's usually 10 ways to do the same thing, so you're never completely stuck, you'll just get an error which typically has some sensible way to handle.
To spin a positive light on the deprecations, most are replaced with something nicer, so although you have the pain of updating old code, it forces you to be aware of the new approach, which is a silver lining of sorts.
Which further emphasizes the idea of: R might not be the right tool for production processes. I used to fight that concept, but in the past year or so I’ve come to embrace it.
devtools I guess is a solution (write some code to iterate over package requirements), but let me ask you this - how do you protect against breaking changes in devtools?
I have yet to encounter something more reliable than MRAN snapshots https://mran.microsoft.com/documents/rro/reproducibility
Many popular packages like data.table rarely break after years of version upgrades. But relying on that in any kind of programming language is asking for trouble...
We're using renv since about a year at our workplace and haven't had any major issues occur. Maybe try packrat? Or try conda with R. Otherwise using docker should eliminate most reproducibility issues
Let’s say two competent analysts wrote some code 5 years ago and you need to reproduce it today, one in R and the other in Python. The Python code probably includes a `pip freeze` or some equivalent, but the author of the R code had no equivalent. There’s no good agreed upon solution. And I don’t think I could reasonably fault that R analyst.
Packrat seems to be falling out of favor, I should read more about conda with R.
(The way I’d solve this problem in R is with an MRAN snapshot from 5 years back in a Docker image, but that’s basically accepting I won’t be able to integrate it with more recently written R)
Using Reaper I made a simple arpeggiator extension: it takes input from one track for the chords and from another track for the notes, and it maps the notes from the notes track to the available notes from the chords track. It's like a "snap to scale" but it snaps to the current chord.
It's much better than a normal arpeggiator plugin IMHO because you don't have to program patterns in the UI of a plugin; you can do anything in the notes track and it will always work.
The limitation, as with any arpeggiator, is that it can't play notes outside of the current chord (but it's possible to have "chords" with many notes on the chords track to allow more freedom).
One way that I use it is I write a chord progression, then I play over it using the extension, and then I adjust the recording by moving notes to more interesting positions. This song was made this way: https://open.spotify.com/track/5TxVfIf9JUAhCEL3O5cWXT (It's not perfect and the sound is kind of bad, but it's a start).
Less than an arpegiator, I think it's closer to 1/f or fractal iteration.
I've spent the last few days working out a similar hypothesis using a "fractal sequencer" module for my eurorack rig. (https://www.qubitelectronix.com/shop/bloom)
Essential idea is it takes your sequence of notes, creates a bunch of branches that are essentially folds, and then iterates through them. The track linked is two sequences iterating the 1st 3rd 6th 8th of a scale across two different oscillators creating a kind of bleep-bloopy counterpoint in the background, and then adding a manual three note lead with some drum breaks and drops to tie it together. I wanted to see how different fractal randomness sounded from intentional complexity. (https://soundcloud.com/n-gram-music/beatrice) It's still sounds random'ish because it plods, where a real composer would add intention, emphasis, and ornamentation, but it's still within the domain of clearly musical.
I'd say it's based on minimalism and Arvo Part's tintinabuli method, but I think one should be an actual serious musician before making lofty claims like that. (I am not) However, this idea of whether there is a big difference between 1/f fractal complexity in a consonant set of notes, and actual human intent is interesting. I suspect Bach (and before him, Vivaldi) had an underlying system that was based on fractal iterations of each theme, which is what sent me down this (rather nutty) path, but the journey continues to amuse.
Even if the generation itself has limitations it seems like a great springboard for manual touches like dissonance tweaking, or new sections, or fills / transitions -- arguably the cool creative part after all anyway! There's a lot of repetition in music, and when writing, it's hard to decouple it from points of interest. A workflow that enables such is very exciting.
(Taking this opportunity to share my multiplayer piano roll editor: https://yuxshao.github.io/ptcollab/ )