reactive-balsa-0.1: Programmatically edit MIDI events via ALSA and reactive-banana

Safe HaskellNone




helper functions

data Handle Source




sequ :: T DuplexMode
client :: T
portPublic :: T
portPrivate :: T
queue :: T

setTimeStamping :: ReaderT Handle IO ()Source

make ALSA set the time stamps in incoming events

connect :: [String] -> [String] -> ReaderT Handle IO ()Source

Connect ourselve to an input client and an output client. The function expects a list of alternative clients that are checked successively.

send single events



class Events ev whereSource

This class unifies several ways of handling multiple events at once.


flattenEvents :: ev -> [Future Data]Source


Events Data 
Events NoteBoundary 
Events ev => Events [ev] 
Events ev => Events (Maybe ev) 
Events ev => Events (Future ev) 
(Events ev0, Events ev1) => Events (ev0, ev1) 
(Events ev0, Events ev1, Events ev2) => Events (ev0, ev1, ev2) 

data Future a Source

The times are relative to the start time of the bundle and do not need to be ordered.




futureTime :: T
futureData :: a


type Bundle a = [Future a]Source

now :: a -> Future aSource


transpose :: Int -> Data -> Maybe DataSource

Transpose a note event by the given number of semitones. Non-note events are returned without modification. If by transposition a note leaves the range of representable MIDI notes, then we return Nothing.

reverse :: Data -> Maybe DataSource

Swap order of keys. Non-note events are returned without modification. If by reversing a note leaves the range of representable MIDI notes, then we return Nothing.

replaceProgram :: Real i => [i] -> i -> [i] -> (Bool, [i])Source

 > replaceProgram [1,2,3,4] 5 [10,11,12,13]

programFromBanks :: Real i => [i] -> [i] -> iSource

programsAsBanks :: [Int] -> Data -> State [Int] DataSource

Interpret program changes as a kind of bank switches in order to increase the range of instruments that can be selected via a block of patch select buttons.

programAsBanks ns divides the first sum ns instruments into sections of sizes ns!!0, ns!!1, .... Each program in those sections is interpreted as a bank in a hierarchy, where the lower program numbers are the least significant banks. Programs from sum ns on are passed through as they are. product ns is the number of instruments that you can address using this trick. In order to avoid overflow it should be less than 128.

E.g. programAsBanks [n,m] interprets subsequent program changes to a (0<=a<n) and n+b (0<=b<m) as a program change to b*n+a. programAsBanks [8,8] allows to select 64 instruments by 16 program change buttons, whereas programAsBanks [8,4,4] allows to address the full range of MIDI 128 instruments with the same number of buttons.

traversePrograms :: Data -> State [Program] (Maybe Data)Source

Before every note switch to another instrument according to a list of programs given as state of the State monad. I do not know how to handle multiple channels in a reasonable way. Currently I just switch the instrument independent from the channel, and send the program switch to the same channel as the beginning note.

traverseProgramsSeek :: Int -> Data -> State [Program] (Maybe Data)Source

This function extends traversePrograms. It reacts on external program changes by seeking an according program in the list. This way we can reset the pointer into the instrument list. However the search must be limited in order to prevent an infinite loop if we receive a program that is not contained in the list.

controllerFromNote :: (Int -> Int) -> Controller -> Data -> Maybe DataSource

Map NoteOn events to a controller value. This way you may play notes via the resonance frequency of a filter.

splitFraction :: RealFrac a => a -> (Int, a)Source

properFraction is useless for negative numbers

fraction :: RealFrac a => a -> aSource

ctrlDur :: (T, T) -> Int -> TSource

predicates - may be moved to midi-alsa package

event list support

mergeStable :: C time => T time body -> T time body -> T time bodySource

mergeEither :: C time => T time a -> T time b -> T time (Either a b)Source