]> gitweb @ CieloNegro.org - wavpack.git/blobdiff - examples/WvInfo.hs
WVBitstream
[wavpack.git] / examples / WvInfo.hs
index 4c5cf88cf6b6c895021382b9617459467faae16a..75c13ab3076510fefdb241e96c152d6fb3be79ab 100644 (file)
@@ -1,20 +1,44 @@
 {-# LANGUAGE
-    UnicodeSyntax
+    UnboxedTuples
+  , UnicodeSyntax
   #-}
 module Main where
 import Codec.Audio.WavPack.Block
+import Codec.Audio.WavPack.Metadata
 import qualified Data.ByteString.Lazy as L
+import qualified Data.Strict as S
+import Data.Maybe
+import Prelude.Unicode
 import System.Environment
+import System.IO
 
 main ∷ IO ()
 main = do [wvFile] ← getArgs
-          wvStream ← L.readFile wvFile
-          showWvInfo wvStream
+          wvData   ← L.readFile wvFile
+          hSetBuffering stdout NoBuffering
+          showWvInfo wvData
 
 showWvInfo ∷ L.ByteString → IO ()
 showWvInfo stream
-    = case findNextHeader stream of
-        Just (bh, _)
-            → print bh
-        Nothing
+    = case findNextBlock stream of
+        (# S.Just block, _ #)
+            → printBlock block
+        (# S.Nothing   , _ #)
             → fail "Can't find any WavPack block headers."
+
+printBlock ∷ Block → IO ()
+printBlock b
+    = do putStrLn "- Block header:"
+         print $ blockHeader b
+         putStrLn "- Block metadata sub-blocks:"
+         mapM_ printSub $ blockMetadata b
+    where
+      printSub ∷ SubBlock → IO ()
+      printSub sub
+          | isJust (fromSubBlock sub ∷ Maybe WVBitstream)
+              = putStrLn ( "(WV Bitstream omitted: " ⧺
+                           show (metaSize sub) ⧺
+                           " bytes)"
+                         )
+          | otherwise
+              = print sub