RtMidi-0.2.0.0: examples/playback.hs
import Sound.RtMidi (closeDevice, closePort, defaultOutput, openPort, sendMessage, portCount, portName)
import Control.Concurrent (threadDelay)
main :: IO ()
main = do
device <- defaultOutput
numPorts <- portCount device
ports <- mapM (portName device) [0..numPorts-1]
mapM_ (\t -> putStrLn $ show t) $ zip [0..] ports
putStrLn "select port: "
selection <- getLine
openPort device (read selection) "RtMidi"
let arp0 = take 12 $ cycle [0x51, 0x55, 0x58]
let arp1 = take 12 $ cycle [0x51, 0x56, 0x5a]
let arp2 = take 12 $ cycle [0x50, 0x53, 0x58]
let song = cycle (arp0 ++ arp1 ++ arp2 ++ arp0)
putStrLn "playing..."
mapM_ (\x -> sendMessage device [0x90, x, 0x7f] >> threadDelay 120000) $ take 240 song
putStrLn "exiting..."
closePort device
closeDevice device