Skip to content

 使用 Haskell 创作音乐 #4

@raptazure

Description

@raptazure
  1. Mezzo

Mezzo 是一个可以描述音乐的领域内编程语言 / Haskell 库,它可以对不同的音乐创作模式进行静态检查(类似于静态类型检查,这当然也是得益于 Haskell 的类型检查系统),也就是说,如果你创作了“坏”的音乐,你的作曲将不会被编译 – think of it as a very strict spell-checker for music.

import Mezzo

comp = defScore $ start $ melody :| c :| d :| e :| f :>> g

main :: IO ()
main = renderScore "comp.mid" "First composition" comp

Save, build and execute. You should get a .mid file in the project directory which looks something like this:

image

To test the correctness checking, change the d note in comp to a b. You should see the following when you save the file:

• Major sevenths are not permitted in melody: C and B
• In the first argument of ‘(:|)’, namely ‘melody :| c :| b’
  In the first argument of ‘(:|)’, namely ‘melody :| c :| b :| e’
  In the first argument of ‘(:>>)’, namely
    ‘melody :| c :| b :| e :| f_’

Mezzo has two ways of composing music: sequential (melodic) and parallel (harmonic) composition ...

  1. 一本很棒的书: http://euterpea.com/haskell-school-of-music/
  • 使用 Haskell 编程语言探索计算机音乐和函数式编程的基础。
  1. 其他的框架和库:

    th.composer 的一个视频演示:https://github.com/raptazure/presentations/blob/master/haskell-music/music.mp4

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions