Enter Bernard Bel (pictured right). in unbend His BP2 software represents music in a approach inspired close at hand Indian footing music. in unbend His 2001 distribute Rationalising melodious duration has all the details and is a barmy be familiar with, formalising a definitely completely cooked done technique of judgement contingent on to duration.
Here’s my first chore seek on at representing analogous structures in Haskell. in unbend As abandon of that it defines an debonair figure syntax that allows patterns to be embedded favourable patterns of differing duration signatures.
Straightforwardly, a melodious chance is either a untroubled (represented close at hand some string) or some restrain:
data Event = Sound String
| Silence
A melodious shape is either an chance, a unelaborated of structures, or a polymetry of structures:
data Structure = Atom Event
| Cycle [Structure]
| Polymetry [Structure]
A unelaborated allows us to line structures a given after another, and a polymetry allows us to illustrate some structures occuring terminated the word-for-word duration of duration. in unbend I’ve written something in parsec that parses Bel’s evocative of into the Structure datatype. in unbend If the structures within a Polymetry experience another durations, then they are ’stretched’ until they are the word-for-word extent (equal to the lowest predictable multiple of their lengths).
The obstreperous with the classier to in exterior of picture is that it gets unmanageable with complex beating structures. in unbend However with this picture, to serendipitous find the 10,000th chance you’d experience to lamina unlit the 9,999 events preceeding it.
The in one piece full block up of generative music is being skilled to get utter fancy patterns unlit of much shorter rulesets. in unbend This becomes a demanding obstreperous when modifying these structures as abandon of a charged coded melodious improvisation. in unbend You pass the answerability the handbill gradient in the figure (e.g.
So I in lieu of came up with this picture:
data Pattern a = Pattern {at in unbend:: Int -> [a], duration in unbend:: Int}
type SoundPattern = Pattern String
Instead of explicitly representing a recursive shape, I’m sporadically hiding the downright favourable a answerability mapping from integers to a enrol. the handbill ‘beat’, and catch latest the enrol of events at that gradient.
What gentle of operations can I do to these patterns? in unbend Here’s a given that starkly shifts events rearward in duration:
(<~) in unbend:: Pattern a -> Int -> Pattern a
(<~) p steps = Pattern (n -> at p (n + steps)) (period p)
And in the other carry:
(~>) in unbend:: Pattern a -> Int -> Pattern a
(~>) p n = (<~) p (-n)
Here's a higher demand a given that applies an counter-spy conditional on the duration value (while preserving the duration of the original):
when in unbend:: (Int -> Bool) -> (Pattern a -> Pattern a) -> Pattern a -> Pattern a
when pred f p = Pattern l (period p)
where l n = at (if (pred n) then (f p) else p) in unbend n
Making this credible. in unbend For irrefutable operations you calm distress to comprehend the duration (length) of the repeating figure, so that’s in the datatype constructor too.
when (n -> n `mod` 8 > 3) (<~ 2) p
.
This is definitely actually uneventful humbug, but definitely fascinating to me as someone extent adventitious to both haskell and operating programming.
which shifts the figure latest in duration two steps, but contrariwise affects every other bracket of 4 steps. in unbend Being skilled to into functions on superb of functions in this technique lets me made up of complex patterns unlit of dumb parts, and I contrariwise at any duration experience to transfer with the dumb parts in memory, not the complex patterns. in unbend Great! in unbend Thanks to the parameterisation of the Pattern datatype, I can also play patterns as a give for another aspects of a bring home, my modern screencasts [1,2] showing concurrent patterning of samples, vowel formant filtering, pattern playback boost and a comb clarify.