hmidi-0.2.3.1: Binding to the OS level MIDI services
Safe HaskellSafe-Inferred
LanguageHaskell2010

System.MIDI.Sync

Description

MIDI sync to an external clock source.

To avoid confusion: In our terminology, beat means a quarter note (the same thing as the B in BPM). In MIDI terminology however, a "MIDI beat" means a sixteenth note.

With our notion of beats, one bar is 4 beats (in 4/4 signature, that is)

Synopsis

Documentation

type Beats = Double Source #

Song position measured in beats (that is, quarter notes), starting from zero. So with 120 BPM, you will have song position 120 after one minute.

type BPM = Double Source #

Estimated BPM

openSourceWithSync Source #

Arguments

:: Source

midi source

-> (BPM -> Maybe Beats -> MidiEvent -> IO ())

user callback

-> IO (Connection, IO (Maybe Beats), IO BPM)

(connection, song_position, estimated_bpm)

Opens a midi source with the possibility to sync to it.

The user callback gets the the song position in beats, and also we return functions to query to song position and the estimated BPM. You may want to round the BPM to the nearest integer if that is appropriate. Song position is Nothing when the playback is stopped.

Note that when first used, it may need some time to calibrate the bpm correctly, so start your MIDI host, press play, and wait a few second. Afterwards, it should be reasonably ok. Also if you do fast realtime BPM changes, it will be a tiny little bit behind.

Note that we forward all messages (including clock messages) to the user, so you can implement your own handling of transport (startstopcontinue) or send messages on clock if you want.