Karya, built on 2018-03-16T03:22:32 (patch df7306861219887e676081746f4a4edfe05eb0b5)

Safe HaskellNone




Support for generating and parsing sysex files from a "spec" file.

TODO I need to support disjoint subsections, e.g. the different effects blocks depending on the value of an enum.


parse files

parse_dir :: [Parser [Patch]] -> FilePath -> IO [Patch] Source #

For every file below the directory ending with .syx, try all of the given parsers on it.

parse_builtins :: Int -> Parser [Patch] -> FilePath -> IO [Patch] Source #

Parse a file just like parse_file. But this file is expected to be the dump of the patches currently loaded in the synthesizer, and will be given ProgramChange msgs for initialization rather than sysex dumps.

try_parsers :: [Parser a] -> B.ByteString -> Either.Either String a Source #

Try each parser in turn, and fail only if they all fail.

initialize_program :: Int -> Midi.Program -> Patch -> Patch Source #

Assume the sysex midi channel is 0.


data Record Source #


RMap RMap

A List is represented as an RMap with numbered keys.

RUnion RMap

Which one this is is determined by an RStr elsewhere.

RNum Int 
RStr Text 
RUnparsed B.ByteString 

spec_to_rmap :: Specs -> RMap Source #

Create a Record from a Spec, defaulting everything to 0, "", or the first enum val.

show_flat :: RMap -> [String] Source #

Show an RMap as a flat list of paths and values.

put_rmap :: (Show a, RecordVal a) => String -> a -> RMap -> Either.Either String RMap Source #

Put the given val into the rmap at a certain path. This only modifies existing fields, it won't create new ones, and you can't change the type of a field.


extract_sysex :: B.ByteString -> [B.ByteString] Source #

Extract substrings delimited by sox_byte and eox_byte. Bytes not within the delimeters are stripped.


data Config Source #




config_8bit :: Config Source #

Encode for 8bit bytes, where numbers are never more than 1 byte.



bit fiddling

to_signed :: (Integral a, Bits.Bits a) => Int -> a -> Int Source #

Convert an n bit 2s complement word to a signed integer.

from_signed :: Int -> Int -> Word8 Source #

Convert a signed integer to an n bit 2s complement word.


type Specs = [(Name, Spec)] Source #

data Spec Source #


Bits [(Name, BitField)]

A set of bitfields encoded in a single byte. The BitField widths must add up to 8. They start at the least significant end of the byte, so given [("a", (1, Range 0 1)), ("b", (7, Range 0 1))], a is from the least significant bit.

Num Range 
Str Bytes 
SubSpec Specs 
List Int Specs 
Union Name Bytes [(EnumName, Specs)]

The content of this section depends on a previous enum value. The Name is the name of the enum to reference

Unparsed Bytes

A chunk of unparsed bytes. If the name is "", then its considered unused padding. On input it will be ignored, and on output will become zeros.

Constant B.ByteString

Assert that these bytes are set literally. This is useful for failing quickly when the required header isn't found.


Show Spec # 


showsPrec :: Int -> Spec -> ShowS #

show :: Spec -> String #

showList :: [Spec] -> ShowS #

data Range Source #


Range Int Int 
Enum [EnumName] 


type NumRange = (Int, Int) Source #

type Bits = Int Source #

type Bytes = Int Source #

assert_valid :: Config -> String -> Int -> Specs -> Specs Source #

Hokey runtime check to make sure the Specs is valid and has the expected size.