Once you have Euterpea and possibly HSoM installed, it’s a good idea to try some really simple things first. If you have any trouble with these, please take a look at the troubleshooting section at the bottom of the download and installation page.
Play Some Notes
- Mac/Linux users: open your synthesizer! It must be running first to hear sound from Euterpea.
- Open a command prompt or terminal and run ghci to start the Haskell interpreter.
import Euterpeaand wait for all of the modules to load.
play $ c 4 qnand listen. You should hear a single tone.
- Want more notes? Try this:
play $ line [c 4 qn, c 4 qn, g 4 qn, g 4 qn, a 4 qn, a 4 qn, g 4 hn]
Recognize the melody?
Notes from a Musical GUI (Requires the HSoM Library)
- Open a command prompt or terminal and start ghci as above. Mac/Linux users: make sure your synthesizer is open!
import HSoM.Examples.MUIExamples2and wait for all of the modules to load.
bifurcateand wait for a window to pop up (it can take a few seconds to load fully). You should see a bunch of sliders an text fields with changing values, and you should hear notes periodically.
- Move the sliders to hear some crazy stuff.
A collection of supplemental code examples is available on GitHub. These are different from the examples covered in the Haskell School of Music textbook. Download the examples here and try editing them to explore how the changes affect what you hear – experimentation is one of the best ways to learn a new library! You can also check out the Examples folder of the HSoM library, which contains all of the code examples from the textbook, but without the accompanying descriptions.
Euterpea 2 Examples
The following supplemental examples can be downloaded from GitHub. Please note that these examples are not meant to fully replace the textbook or other basic tutorials on the Haskell programming language as a means of learning Haskell and Euterpea.
To run the source code in the examples below, you need to first save the source files (either .lhs or .hs) to your computer. Then, open a command prompt, PowerShell, or terminal, and cd to the directory where you saved the source files. Start the GHCi interpreter (run
ghci) and then run
:load FileName.lhs to load the file you want. You can then access any functions or values the file defines from within the interpreter. Windows users can also simply double-click the source file to open it with GHCi (as long as you haven’t altered the default “open with” settings for .lhs and .hs files).
- Note-level examples: making music with MIDI.
- Signal-level examples: generating sound as WAV files.
- Musical User Interface (MUI) Examples: interactive MIDI programs.
- SimpleGUIs – examples of using UISF widgets, which are the foundation of HSoM’s MUIs. Many of these do not produce sound and just illustrate the usage of individual graphical widgets in a simple setting.
- DrumMUI – a small drum machine MUI that allows the user to select one of several patterns to play and the tempo.
- Interactive Stochastic Music (MIDI input required) – a Haskell port of a JythonMusic program for interactive music generation. Input from a MIDI controller is taken in real-time and used to generate new sequences.
- HaskellOx – a program that routs MIDI messages between devices and demonstrates two methods for implementing this functionality. The linked zip file includes both the source and a compiled executable for Windows. See the batch file for the best compilation method.
The Haskell School of Music textbook offers a simultaneous introduction to the Haskell programming language and the Euterpea library. However, that’s not the only way to learn the language and library. You can follow some other online Haskell tutorials to familiarize yourself with the basic syntax of the language, then take a look at the Euterpea API pages, and browse through the code in the Euterpea library itself (all of which is open source). Some useful online tutorials are linked to below.