Euterpea library to create music with Haskell

Hey guys,

I’m currently trying to play some notes with the Haskell Euterpea library. I’m using yoshimi as a synthesizer software. My Problem is, for some odd reason the first note gets skipped, only the second, third and so on are played. No matter what melody I try to play, its always the same. Someone has the same problem or an idea how to fix it?


module Main (main) where                                                                                                                                                                                                                                                                                                                                                             

import Euterpea  

hNote          :: Dur -> Pitch -> Int -> Music Pitch                                                                                                                                       
hNote d p h = note d p :=: note d (trans (-h) p)                                                                                                                
                                                                                                                                                                                             
mel :: Music Pitch                                                                                                                                                                    
mel = hNote qn (F,4) 3 :+: hNote qn (A,4) 4 :+: hNote qn (F,4) 3                                                                                                             
                                                                                                                                                                                                                                                                                                                                    
main :: IO()                                                                                                                                                                                 
main = do                                                                                                                                                                                                                                                                                                                                                                 
     play mel

Thank u for any help :slight_smile:

If you sandwich your code block between ```, your post will be easier to read.

I have a similar problem when I dabble with ABC notation. The first note of the resulting .midi does not get played on some synthesizers.

I work around it by adding a very small pause at the beginning of the piece. Maybe this will work with Euterpea too?

Thank u for your suggestion, I just edited the post :slight_smile:

I also thought about some workaround like adding a small pause or a dummy note in front of my melody.
Was just wondering if there’s a more elegant way to fix this, but maybe its a problem with yoshimi then.

Just tried to add a small pause at the beginning of my melody, but actually that’s not working. The next note will also be skipped and only the third and fourth note will be played. That’s fairly weird.

Here’s my code with the pause (I also added the same pause in between the third and fourth note just for testing if the pause works).


import Euterpea  

hNote          :: Dur -> Pitch -> Int -> Music Pitch                                                                                                                                       
hNote d p h = note d p :=: note d (trans (-h) p)                                                                                                                
                                                                                                                                                                                             
mel :: Music Pitch                                                                                                                                                                    
mel = wnr :+: hNote qn (F,4) 3 :+: hNote qn (A,4) 4 :+: wnr :+: hNote qn (F,4) 3                                                                                                             
                                                                                                                                                                                                                                                                                                                                    
main :: IO()                                                                                                                                                                                 
main = do                                                                                                                                                                                                                                                                                                                                                                 
     play mel

Can Euterpea export a .midi?

in ghci :
- I played the file (i.e. saved in music.hs) using my piano (BlueTooth MIDI #7),

  • saved to a midi file called music.midi and
  • opened the file using MuseScore
Loaded package environment from /Users/me/.ghc/aarch64-darwin-9.6.6/environments/default
GHCi, version 9.6.6: 
  :? for help
ghci> :l music.hs
 [1 of 2] Compiling Main             ( music.hs, interpreted )
Ok, one module loaded.
ghci> devices
  Input devices: 
     InputDeviceID 0 IAC Driver Bus 1
     InputDeviceID 1 Network RTP Session 1
     InputDeviceID 2 UMP Network Network MIDI 2.0 Session 1
     InputDeviceID 3 FP-30 Bluetooth
  Output devices: 
     OutputDeviceID 4 IAC Driver Bus 1
     OutputDeviceID 5 Network RTP Session 1
     OutputDeviceID 6 UMP Network Network MIDI 2.0 Session 1
     OutputDeviceID 7 FP-30 Bluetooth
ghci> playDev 7 mel
ghci> writeMidi "music.midi" mel
ghci> :q
Leaving GHCi.

% open music.midi 

This is what is displayed in MuseScore