diff options
author | Andrew Cady <d@jerkface.net> | 2014-01-14 04:43:07 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2014-01-14 04:43:07 -0500 |
commit | d95475d8c16d1baf066492e36ed6ebe8866bba31 (patch) | |
tree | 902477982446bfd4507d6ddd0ef86b9962784f0f /midi-dump.hs | |
parent | 038e1c72be72a5f2138cdf725560369c5994e147 (diff) |
add midi-dump experimental code
Diffstat (limited to 'midi-dump.hs')
-rw-r--r-- | midi-dump.hs | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/midi-dump.hs b/midi-dump.hs new file mode 100644 index 0000000..3652162 --- /dev/null +++ b/midi-dump.hs | |||
@@ -0,0 +1,80 @@ | |||
1 | import qualified Sound.ALSA.Sequencer.Client as Client | ||
2 | import qualified Sound.ALSA.Sequencer.Port as Port | ||
3 | import qualified Sound.ALSA.Sequencer.Event as Event | ||
4 | import qualified Sound.ALSA.Sequencer as SndSeq | ||
5 | import qualified Sound.ALSA.Exception as AlsaExc | ||
6 | import Control.Monad (forever, ) | ||
7 | |||
8 | |||
9 | import qualified Sound.ALSA.Sequencer.Client.Info as ClientInfo | ||
10 | import qualified Sound.ALSA.Sequencer.Port.Info as PortInfo | ||
11 | import qualified Sound.ALSA.Sequencer.Port as Port | ||
12 | import qualified Data.EnumSet as EnumSet | ||
13 | import Text.Printf (printf, ) | ||
14 | import Control.Monad (liftM5, liftM2, join, when, filterM, forM_) | ||
15 | |||
16 | import Sound.ALSA.Sequencer.Connect as AlsaConn | ||
17 | |||
18 | |||
19 | listPorts :: IO () | ||
20 | listPorts = do | ||
21 | putStrLn " Port Client name Port name Caps" | ||
22 | SndSeq.withDefault SndSeq.Block $ \h -> | ||
23 | ClientInfo.queryLoop_ (h :: SndSeq.T SndSeq.OutputMode) $ \cinfo -> do | ||
24 | client <- ClientInfo.getClient cinfo | ||
25 | PortInfo.queryLoop_ h client $ \pinfo -> do | ||
26 | join $ liftM5 (\a b c d e -> when (c == "AXIS-49 2A") $ printf "%3d:%-3d %-32.32s %-24.24s %s\n" a b c d e) | ||
27 | (fmap (\(Client.Cons p) -> p) $ PortInfo.getClient pinfo) | ||
28 | (fmap (\(Port.Cons p) -> p) $ PortInfo.getPort pinfo) | ||
29 | (ClientInfo.getName cinfo) | ||
30 | (PortInfo.getName pinfo) | ||
31 | (do | ||
32 | caps <- PortInfo.getCapability pinfo | ||
33 | let disp (cap, char) = | ||
34 | if EnumSet.disjoint caps cap then ' ' else char | ||
35 | return $ map disp $ | ||
36 | (Port.capRead, 'r') : | ||
37 | (Port.capSubsRead, 'R') : | ||
38 | (Port.capWrite, 'w') : | ||
39 | (Port.capSubsWrite, 'W') : | ||
40 | []) | ||
41 | |||
42 | findPort wantName f = do | ||
43 | SndSeq.withDefault SndSeq.Block $ \h -> | ||
44 | ClientInfo.queryLoop_ (h :: SndSeq.T SndSeq.OutputMode) $ \cinfo -> do | ||
45 | name <- (ClientInfo.getName cinfo) | ||
46 | when (name == wantName) $ do | ||
47 | client <- ClientInfo.getClient cinfo | ||
48 | PortInfo.queryLoop_ h client $ \pinfo -> do | ||
49 | port <- (fmap (\(Client.Cons p) -> p) $ PortInfo.getClient pinfo) | ||
50 | f port | ||
51 | |||
52 | main :: IO () | ||
53 | main = (do | ||
54 | --outport <- findPort "AXIS-49 2A" return -- nope | ||
55 | --outport <- findPort "AXIS-49 2A" (\p -> return p) -- nope | ||
56 | putStrLn "Starting." | ||
57 | SndSeq.withDefault SndSeq.Nonblock $ \h -> do | ||
58 | Client.setName (h :: SndSeq.T SndSeq.InputMode) "Axis-of-Eval" | ||
59 | putStrLn "Created sequencer." | ||
60 | Port.withSimple h "primary" | ||
61 | (Port.caps [Port.capWrite, Port.capSubsWrite]) Port.typeMidiGeneric $ \ _p1 -> do | ||
62 | Port.withSimple h "secondary" | ||
63 | (Port.caps [Port.capWrite, Port.capSubsWrite]) Port.typeMidiGeneric $ \ _p2 -> do | ||
64 | putStrLn "Created ports." | ||
65 | |||
66 | clientPointer <- ClientInfo.get h | ||
67 | clientID_Cons <- ClientInfo.getClient clientPointer | ||
68 | clientID <- (\(Client.Cons p) -> return p) clientID_Cons | ||
69 | |||
70 | findPort "AXIS-49 2A" (connectAxis clientID) | ||
71 | |||
72 | when False $ do | ||
73 | forever $ do | ||
74 | putStrLn "waiting for an event:" | ||
75 | print =<< Event.input h) | ||
76 | `AlsaExc.catch` \e -> | ||
77 | putStrLn $ "alsa_exception: " ++ AlsaExc.show e | ||
78 | |||
79 | connectAxis myID axisID = do | ||
80 | printf "Found my ID: %d.\nFound Axis ID: %d.\n" myID axisID | ||