Skip to content

Instantly share code, notes, and snippets.

@ludflu
Created November 22, 2017 13:41
Show Gist options
  • Select an option

  • Save ludflu/a8be929b4a04384f6ecbcee4f582c2a1 to your computer and use it in GitHub Desktop.

Select an option

Save ludflu/a8be929b4a04384f6ecbcee4f582c2a1 to your computer and use it in GitHub Desktop.
music
import Euterpea
import System.Random
import Data.Map hiding (map,foldr,foldl)
fisherYatesStep :: RandomGen g => (Map Int a, g) -> (Int, a) -> (Map Int a, g)
fisherYatesStep (m, gen) (i, x) = ((insert j x . insert i (m ! j)) m, gen')
where
(j, gen') = randomR (0, i) gen
fisherYates :: RandomGen g => g -> [a] -> ([a], g)
fisherYates gen [] = ([], gen)
fisherYates gen l =
toElems $ foldl fisherYatesStep (initial (head l) gen) (numerate (tail l))
where
toElems (x, y) = (elems x, y)
numerate = zip [1..]
initial x gen = (singleton 0 x, gen)
dMinor = d 4 wn :=: f 4 wn :=: a 4 wn
gMajor = g 4 wn :=: b 4 wn :=: d 5 wn
cMajor = c 4 bn :=: e 4 bn :=: g 4 bn
t251 = dMinor :+: gMajor :+: cMajor
notes = [c,d,e,f,g,a,b]
l = map (\x -> x 4 hn) notes
m = foldr (:+:) (rest hn) l
main = do g <- getStdGen
let (sf,bla) = fisherYates g [60..71]
nnotes = map (\x -> note en $ pitch x) sf
msc = foldr (:+:) (rest hn) nnotes
playDev 2 $ msc
playDev 2 $ msc
print msc
--main = playDev 2 $ c 4 wn
--main = playDev 2 $ t251
--main = playDev 2 m
@phroniaphronia

phroniaphronia commented Feb 1, 2024

Copy link
Copy Markdown

awesome dude. Through this, I can also create sonnerie telephone songs. It's great to know about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment