Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drawing the tree structure of a score #49

Open
jwaldmann opened this issue Dec 9, 2021 · 0 comments
Open

drawing the tree structure of a score #49

jwaldmann opened this issue Dec 9, 2021 · 0 comments

Comments

@jwaldmann
Copy link

jwaldmann commented Dec 9, 2021

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant