diff options
author | Andrew Cady <d@jerkface.net> | 2014-01-15 12:33:04 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2014-01-15 12:33:04 -0500 |
commit | d81a2d23d58e8cd9178ad21f802730d2fce31e40 (patch) | |
tree | 8cb728d8b3f2b8c62f00cb2721bbe08413337445 | |
parent | 98a3be73f6fa8a8e3f998dd3ace2efab34aa38b8 (diff) |
add alsa initialization to axis.hs
-rw-r--r-- | AlsaSeq.hs | 4 | ||||
-rw-r--r-- | axis.hs | 11 | ||||
-rw-r--r-- | midi-dump.hs | 2 |
3 files changed, 9 insertions, 8 deletions
@@ -1,4 +1,4 @@ | |||
1 | module AlsaSeq (alsaInit, parseAlsaEvents, forwardNoteEvent, cmdlineAlsaConnect, printChordLn) where | 1 | module AlsaSeq (withAlsaInit, parseAlsaEvents, forwardNoteEvent, cmdlineAlsaConnect, printChordLn) where |
2 | import qualified Sound.ALSA.Exception as AlsaExc | 2 | import qualified Sound.ALSA.Exception as AlsaExc |
3 | import qualified Sound.ALSA.Sequencer.Address as Addr | 3 | import qualified Sound.ALSA.Sequencer.Address as Addr |
4 | import qualified Sound.ALSA.Sequencer as SndSeq | 4 | import qualified Sound.ALSA.Sequencer as SndSeq |
@@ -69,7 +69,7 @@ alsaClientPorts h cinfo = do | |||
69 | return p | 69 | return p |
70 | return ports | 70 | return ports |
71 | 71 | ||
72 | alsaInit k = do | 72 | withAlsaInit k = do |
73 | SndSeq.withDefault SndSeq.Nonblock $ \h -> do | 73 | SndSeq.withDefault SndSeq.Nonblock $ \h -> do |
74 | 74 | ||
75 | Client.setName (h :: SndSeq.T SndSeq.DuplexMode) "Haskell Beats" -- In imperative language MIDI sequencer, you rock beat. In Haskell language MIDI sequencer, rock beat you! | 75 | Client.setName (h :: SndSeq.T SndSeq.DuplexMode) "Haskell Beats" -- In imperative language MIDI sequencer, you rock beat. In Haskell language MIDI sequencer, rock beat you! |
@@ -5,6 +5,8 @@ import Control.Wire hiding (when) | |||
5 | import Control.Wire.Session | 5 | import Control.Wire.Session |
6 | import Control.Monad | 6 | import Control.Monad |
7 | import qualified Graphics.UI.SDL as SDL | 7 | import qualified Graphics.UI.SDL as SDL |
8 | import AlsaSeq | ||
9 | import qualified Data.Set as Set | ||
8 | 10 | ||
9 | netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String | 11 | netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String |
10 | netwireIsCool = | 12 | netwireIsCool = |
@@ -19,17 +21,16 @@ netwireIsCool = | |||
19 | holdFor 0.5 . periodic 1 . pure "Hoo..." <|> | 21 | holdFor 0.5 . periodic 1 . pure "Hoo..." <|> |
20 | pure "...ray!" | 22 | pure "...ray!" |
21 | 23 | ||
22 | --main :: IO () | 24 | main = SDL.withInit [SDL.InitVideo, SDL.InitTimer, SDL.InitJoystick] $ |
23 | --main = testWire clockSession_ netwireIsCool | 25 | withAlsaInit $ \h public private q publicAddr privateAddr -> do |
24 | 26 | putStrLn "Initialized." | |
25 | main = SDL.withInit [SDL.InitVideo, SDL.InitTimer, SDL.InitJoystick] $ do | ||
26 | loop clockSession_ netwireIsCool "" | 27 | loop clockSession_ netwireIsCool "" |
27 | where | 28 | where |
28 | loop s w x = do | 29 | loop s w x = do |
29 | (ds, s') <- stepSession s | 30 | (ds, s') <- stepSession s |
30 | (ex, w') <- stepWire w ds (Right x) | 31 | (ex, w') <- stepWire w ds (Right x) |
31 | let x' = either (const "") id ex | 32 | let x' = either (const "") id ex |
32 | Control.Monad.when (x /= x' && x /= "") $ putStrLn x | 33 | Control.Monad.when (x /= x' && x' /= "") $ putStrLn x' |
33 | let framerate = 30 | 34 | let framerate = 30 |
34 | let delay = 1000 `div` framerate - 1000 * (floor $ dtime ds) | 35 | let delay = 1000 `div` framerate - 1000 * (floor $ dtime ds) |
35 | SDL.delay (delay) | 36 | SDL.delay (delay) |
diff --git a/midi-dump.hs b/midi-dump.hs index 3de065b..51ebc6b 100644 --- a/midi-dump.hs +++ b/midi-dump.hs | |||
@@ -5,7 +5,7 @@ import qualified Data.Set as Set | |||
5 | 5 | ||
6 | main = (do | 6 | main = (do |
7 | 7 | ||
8 | alsaInit $ \h public private q publicAddr privateAddr -> do | 8 | withAlsaInit $ \h public private q publicAddr privateAddr -> do |
9 | cmdlineAlsaConnect h public | 9 | cmdlineAlsaConnect h public |
10 | 10 | ||
11 | let | 11 | let |