hscdio-0.1.0.0: Haskell bindings to the libcdio disc-reading library.
Copyright(c) 2019-2021 Sam May
LicenseGPL-3.0-or-later
Maintainerag@eitilt.life
Stabilitystable
Portabilitynon-portable (requires libcdio)
Safe HaskellNone
LanguageHaskell2010

Sound.Libcdio.Read.CdText

Description

Metadata is stored in a binary format both library-internally and on the disc. Most audio archivists will recognize it as "those information fields in a CUE file" (though there are other formats as well), and casual listeners will recognize it as the scrolling text that you're always happy to see, on the rare times your music player shows it. Little-used and even-less-known, however, is that a single disc can theoretically contain metadata in up to eight different languages; because of the complexity that introduces, it makes more sense to use a second monadic interface than to try to provide a single monolithic datatype within Cdio.

Synopsis

Types

data CdText a Source #

A computation within the environment of metadata (in a particular language) stored on a CD. The options for affecting that environment from within are limited by design, as this library is intended for reading discs rather than authoring them.

Instances

Instances details
Monad CdText Source # 
Instance details

Defined in Sound.Libcdio.Read.CdText

Methods

(>>=) :: CdText a -> (a -> CdText b) -> CdText b #

(>>) :: CdText a -> CdText b -> CdText b #

return :: a -> CdText a #

Functor CdText Source # 
Instance details

Defined in Sound.Libcdio.Read.CdText

Methods

fmap :: (a -> b) -> CdText a -> CdText b #

(<$) :: a -> CdText b -> CdText a #

MonadFail CdText Source #

Wraps the text in a FreeformCdTextError, for recovery with catchError.

Instance details

Defined in Sound.Libcdio.Read.CdText

Methods

fail :: String -> CdText a #

Applicative CdText Source # 
Instance details

Defined in Sound.Libcdio.Read.CdText

Methods

pure :: a -> CdText a #

(<*>) :: CdText (a -> b) -> CdText a -> CdText b #

liftA2 :: (a -> b -> c) -> CdText a -> CdText b -> CdText c #

(*>) :: CdText a -> CdText b -> CdText b #

(<*) :: CdText a -> CdText b -> CdText a #

Alternative CdText Source #

empty fails with CdTextEmpty.

Instance details

Defined in Sound.Libcdio.Read.CdText

Methods

empty :: CdText a #

(<|>) :: CdText a -> CdText a -> CdText a #

some :: CdText a -> CdText [a] #

many :: CdText a -> CdText [a] #

LibcdioLogger CdText Source # 
Instance details

Defined in Sound.Libcdio.Read.CdText

MonadError CdTextError CdText Source # 
Instance details

Defined in Sound.Libcdio.Read.CdText

data CdTextError Source #

Associates a well-typed error with human-readable context information.

data CdTextErrorType Source #

Potential situations which may cause a computation to fail.

Constructors

InvalidBlock Word

The requested language index is outside of the bounds accessible by the library ([0..7] in libcdio 2.1 and after, or the smaller range of languages returned by languages before that version).

LanguageNotFound Language

The CdText data does not contain the requested language, or UnknownLanguage was requested (prior to libcdio 2.1 there was no way to select the latter blocks; even after that version, withIndex must be used instead).

BadBinaryRead

The binary data can not be parsed into a CdText object.

NoCdText

The CD contains no CdText data.

CdTextEmpty

empty was called and no better alternative was encountered.

FreeformCdTextError Text

Escape hatch from structured typing to allow user-specified (and user-triggered) errors.

data Info Source #

Textual metadata describing a single track on a disc, or the disc itself.

Constructors

Info 

Fields

Instances

Instances details
Eq Info Source # 
Instance details

Defined in Sound.Libcdio.Read.CdText

Methods

(==) :: Info -> Info -> Bool #

(/=) :: Info -> Info -> Bool #

Read Info Source # 
Instance details

Defined in Sound.Libcdio.Read.CdText

Show Info Source #

Modeled after the standard record syntax, but omitting any Nothing fields for space reasons.

Instance details

Defined in Sound.Libcdio.Read.CdText

Methods

showsPrec :: Int -> Info -> ShowS #

show :: Info -> String #

showList :: [Info] -> ShowS #

emptyInfo :: Info Source #

An Info object with values suitable as defaults.

data Genre Source #

Genres recognized in the CD Text standard.

Instances

Instances details
Bounded Genre Source # 
Instance details

Defined in Foreign.Libcdio.Types.Enums

Enum Genre Source # 
Instance details

Defined in Foreign.Libcdio.Types.Enums

Eq Genre Source # 
Instance details

Defined in Foreign.Libcdio.Types.Enums

Methods

(==) :: Genre -> Genre -> Bool #

(/=) :: Genre -> Genre -> Bool #

Ord Genre Source # 
Instance details

Defined in Foreign.Libcdio.Types.Enums

Methods

compare :: Genre -> Genre -> Ordering #

(<) :: Genre -> Genre -> Bool #

(<=) :: Genre -> Genre -> Bool #

(>) :: Genre -> Genre -> Bool #

(>=) :: Genre -> Genre -> Bool #

max :: Genre -> Genre -> Genre #

min :: Genre -> Genre -> Genre #

Read Genre Source # 
Instance details

Defined in Foreign.Libcdio.Types.Enums

Show Genre Source # 
Instance details

Defined in Foreign.Libcdio.Types.Enums

Methods

showsPrec :: Int -> Genre -> ShowS #

show :: Genre -> String #

showList :: [Genre] -> ShowS #

data Language Source #

Written languages recognized in the CD Text standard.

Evaluation

cdText :: CdText a -> Cdio (Either CdTextError a) Source #

Run the given computation within the CdText data associated with the Cdio session. At this top level, a withIndex 0 specifically will almost always have the same effect as running the computation directly. Fails with NoCdText if the disc doesn't provide any metadata.

parseCdText :: ByteString -> CdText a -> IO (Either CdTextError a) Source #

Given a binary stream, attempt to parse it as a CdText block and run the given computation. Returns Left BadBinaryRead if that parse fails. At this top level, a withIndex 0 specifically will almost always have the same effect as running the computation directly.

Note that binary CdText dumps will frequently include four bytes at the beginning indicating the size of the file; this implementation expects that those bytes are not included. If your dump does indeed begin with them, drop 4 before passing the ByteString to this function.

Before libcdio 0.94: Always returns Left BadBinaryRead

withLanguage :: Language -> CdText a -> CdText a Source #

Try to use a specific language as the context for the given computation; as this will frequently fail with LanguageNotFound if given anything other than English, it is recommended that you provide a fallback with <|> or at least allow recovery with optional. Note that UnknownLanguage will always fail.

withIndex :: Word -> CdText a -> CdText a Source #

Run the given computation over the data in a specific block. Fails with InvalidBlock if the index can't be accessed.

withAll :: CdText a -> CdText [Maybe a] Source #

Run the given computation over all of the accessible languages in the CdText data. When successful, the resulting list can be associated exactly with the list of languages:

>>> ls <- 'languages'
>>> Right ls' <- 'cdText' $ 'withAll' 'language'
>>> ls == ls'
True

runCdText :: Cdio -> CdText a -> IO (Either CdTextError a) Source #

Use a C-style Cdio object as the base to run a Haskell-style CdText computation.

Note that some invariants of the monadic interface may not work as expected when used with the mutable objects, usually due to changing the active language block:

l  <- language cdio
_  <- runCdText cdio $ withIndex i g
l' <- language cdio
(l == l') == undefined

Data

language :: CdText Language Source #

Get the language in which any info is currently being retrieved.

languages :: Cdio [Maybe Language] Source #

List every language with associated data in the CdText data associated with the session. Drops any UnknownLanguage values from the end of the list. For a version which operates within the CdText monad, the construction withAll language will have an identical effect.

Before libcdio 2.1.0: Silently drops any Nothing or Just UnknownLanguage values, even in the middle of the list, and only lists any single language a maximum of one time.

firstTrack :: CdText Track Source #

The earliest track with any associated metadata in the current language. Note that this may differ from minTrack which gives the first track on the disk, CDTEXT or not.

lastTrack :: CdText Track Source #

The final track with any associated metadata in the current language. Note that this may differ from maxTrack which gives the last track on the disc, CDTEXT or not.

info :: Maybe Track -> CdText Info Source #

Retrieve the collection of data associated with a specific track, or if Nothing, the disc itself.

discId :: CdText (Maybe Text) Source #

Publisher-specific catalogue number, or some other context-specific identifier. Note that this may be different than code $ info Nothing which is (assumed to be) the unambiguous bar code unique to this disc release.

genre :: CdText (Maybe Genre, Maybe Text) Source #

The genre describing the music on this disc, and any associated human-readable name or subgenre.

cdTextRaw :: Cdio (Maybe ByteString) Source #

Get the raw binary data making up the CdText data, if any exists on the disc.