Karya, built on 2023-08-29T07:47:28 (patch 7a412d5d6ba4968ca4155ef276a062ccdeb9109a)
Safe HaskellSafe-Inferred

Instrument.Sysex

Description

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.

Synopsis

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.

record

data Record Source #

Constructors

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 

Instances

Instances details
Show Record Source # 
Instance details

Defined in Instrument.Sysex

Eq Record Source # 
Instance details

Defined in Instrument.Sysex

Methods

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

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

Pretty.Pretty Record Source # 
Instance details

Defined in Instrument.Sysex

data RecordType Source #

Constructors

TMap 
TUnion 
TNum 
TStr 
TUnparsed 

Instances

Instances details
Show RecordType Source # 
Instance details

Defined in Instrument.Sysex

Eq RecordType Source # 
Instance details

Defined in Instrument.Sysex

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.

class RecordVal a where Source #

Methods

from_val :: a -> Record Source #

to_val :: Record -> Maybe a Source #

Instances

Instances details
RecordVal Word8 Source # 
Instance details

Defined in Instrument.Sysex

RecordVal B.ByteString Source # 
Instance details

Defined in Instrument.Sysex

RecordVal Text Source # 
Instance details

Defined in Instrument.Sysex

RecordVal Int Source # 
Instance details

Defined in Instrument.Sysex

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.

util

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

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

config

data Config Source #

Constructors

Config 

Fields

config_8bit :: Config Source #

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

encode

decode

bit fiddling

to_signed :: (Integral a, 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.

spec

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

data Spec Source #

Constructors

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.

Instances

Instances details
Show Spec Source # 
Instance details

Defined in Instrument.Sysex

Methods

showsPrec :: Int -> Spec -> ShowS #

show :: Spec -> String #

showList :: [Spec] -> ShowS #

data Range Source #

Constructors

Range Int Int 
Enum [EnumName] 

Instances

Instances details
Show Range Source # 
Instance details

Defined in Instrument.Sysex

Methods

showsPrec :: Int -> Range -> ShowS #

show :: Range -> String #

showList :: [Range] -> ShowS #

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.

convenience

num

bits