From: PHO Date: Wed, 5 Jan 2011 14:42:39 +0000 (+0900) Subject: instance Metadata SubBlock X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=wavpack.git;a=commitdiff_plain;h=a9eea84e339487b166f91d042f390f10a21f47e5 instance Metadata SubBlock --- diff --git a/Codec/Audio/WavPack/Metadata.hs b/Codec/Audio/WavPack/Metadata.hs index edf76f2..f7dc2a0 100644 --- a/Codec/Audio/WavPack/Metadata.hs +++ b/Codec/Audio/WavPack/Metadata.hs @@ -6,7 +6,7 @@ -- | WavPack metadata sub-blocks module Codec.Audio.WavPack.Metadata ( Metadata(..) - , SubBlock(..) + , SubBlock , Dummy(..) , Unknown(..) @@ -21,13 +21,29 @@ import qualified Data.ByteString.Lazy as L import Data.Typeable import Prelude.Unicode +-- | Type class for every metadata sub-blocks. class (Binary α, Eq α, Show α, Typeable α) ⇒ Metadata α where + -- | Get the metadata ID (mandatory). metaID ∷ α → Word8 + -- | Get the size of metadata (optional). metaSize ∷ α → Word32 - metaSize = fromIntegral ∘ L.length ∘ runPut ∘ put + -- | Cast a 'SubBlock' to this type of metadata (optional). + fromSubBlock ∷ SubBlock → Maybe α + fromSubBlock (SubBlock a) = cast a + -- | Wrap the metadata into 'SubBlock' (optional). + toSubBlock ∷ α → SubBlock + toSubBlock = SubBlock +-- | An opaque sub-block container. data SubBlock = ∀α. Metadata α ⇒ SubBlock α + deriving Typeable + +instance Metadata SubBlock where + metaID (SubBlock a) = metaID a + metaSize (SubBlock a) = metaSize a + fromSubBlock = Just + toSubBlock = id instance Binary SubBlock where put (SubBlock a) @@ -84,7 +100,7 @@ instance Show SubBlock where -- | Dummy metadata to pad WavPack blocks. data Dummy = Dummy { - dumSize ∷ !Word32 + dumSize ∷ Word32 } deriving (Eq, Show, Typeable) @@ -99,7 +115,7 @@ instance Binary Dummy where -- | Unknown but optional metadata found in the WavPack block. data Unknown = Unknown { - unkID ∷ !Word8 + unkID ∷ Word8 , unkData ∷ L.ByteString } deriving (Eq, Show, Typeable)