Euterpea / Euterpea2

Euterpea version 2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

drawing the tree structure of a score

jwaldmann opened this issue · comments

I wanted to show the tree structure of a Music1 score. This can be done with https://hackage.haskell.org/package/containers-0.6.5.1/docs/Data-Tree.html#v:drawTree

Do you want to add this, or something like this, to the library? (Well, to some currently living fork, since the original seems to be frozen, cf. https://www.euterpea.com/faq/ "I want to add...")

import Euterpea
import Data.Tree 

toTree :: Show a => Music a -> Tree [Char]
toTree m = case m of 
  Prim p -> Node (show p)[]
  l :+: r -> Node "+" [toTree l, toTree r]
  l :=: r -> Node "=" [toTree l, toTree r]
  Modify m t -> Node (show m) [toTree t]

putStrLn $ drawTree $ toTree $ line [ c 4 en, e 4 en]

+
|
+- Note (1 % 8) (C,4)
|
`- +
   |
   +- Note (1 % 8) (E,4)
   |
   `- Rest (0 % 1)